<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Frage zu new und delete]]></title><description><![CDATA[<p>Hi.</p>
<p>Ist einer dieser Codes &quot;falsch&quot;?<br />
Es geht mir nur um die Position des <strong>delete</strong></p>
<p>Ich schreib das mal so mal so und würde jetzt gern mal wissen ob das falsch ist. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">Lala *x = new Lala();
if (x)
{
//mach was
delete x;
}
</code></pre>
<pre><code class="language-cpp">Lala *x = new Lala();
if (x)
{
//mach was
}
delete x;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/186070/frage-zu-new-und-delete</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 06:30:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/186070.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Jul 2007 16:27:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu new und delete on Wed, 04 Jul 2007 16:27:00 GMT]]></title><description><![CDATA[<p>Hi.</p>
<p>Ist einer dieser Codes &quot;falsch&quot;?<br />
Es geht mir nur um die Position des <strong>delete</strong></p>
<p>Ich schreib das mal so mal so und würde jetzt gern mal wissen ob das falsch ist. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">Lala *x = new Lala();
if (x)
{
//mach was
delete x;
}
</code></pre>
<pre><code class="language-cpp">Lala *x = new Lala();
if (x)
{
//mach was
}
delete x;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1318387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318387</guid><dc:creator><![CDATA[bambus]]></dc:creator><pubDate>Wed, 04 Jul 2007 16:27:00 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu new und delete on Wed, 04 Jul 2007 16:32:36 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Letztendlich machen beide Codes genau dasselbe.<br />
Denn new liefert keinen NULL-Zeiger beim Mißlingen von Speicherreservierung, sondern wirft eine Exception. In dem Fall wird auch in beiden Codes das delete (so wie es hier steht) nicht erreicht und ist auch nicht nötig.<br />
Desweiteren ist ein delete auf einen NULL-Zeiger gültig und hat keine Auswirkung.</p>
<p>Wenn du ganz sicher gehen willst mach das hier</p>
<pre><code class="language-cpp">#include &lt;memory&gt;
...
std::auto_ptr&lt;Lala&gt; x(new Lala());
//mach was
</code></pre>
<p>Allerdings hat auto_ptr auch seine Nachteile : Es ist nicht kopierbar. Das macht im gezeigten Beispiel aber keine Probleme.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318392</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Wed, 04 Jul 2007 16:32:36 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu new und delete on Wed, 04 Jul 2007 16:33:00 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-14774.html" rel="nofollow">akari</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-2.html" rel="nofollow">VCL/CLX (Borland C++ Builder)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318393</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Wed, 04 Jul 2007 16:33:00 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu new und delete on Wed, 04 Jul 2007 17:29:32 GMT]]></title><description><![CDATA[<p>Wenn du nicht willst das der new-Operator eine Exception wirft und dir einen Null-Pointer im Fehlerfall liefert kannst du eine andere Variante verwenden:</p>
<pre><code class="language-cpp">Lala* x = new ( std::nothrow ) Lala(); 

if ( !x ) // jetzt kommt das Programm bis hierhin wenn der Speicher nicht reserviert werden konnte
{
  // mach irgendwas
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1318424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318424</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Wed, 04 Jul 2007 17:29:32 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu new und delete on Wed, 04 Jul 2007 18:03:03 GMT]]></title><description><![CDATA[<p>akari schrieb:</p>
<blockquote>
<p>Allerdings hat auto_ptr auch seine Nachteile : Es ist nicht kopierbar. Das macht im gezeigten Beispiel aber keine Probleme.</p>
</blockquote>
<p>Gemeinerweise ist er ja kopierbar. Die Operation tut nur nicht was man evtl. erwarten könnte (Besitzabgabe). Wenn man auf Nummer sicher gehen will, kann man stattdessen aber std::tr1::scoped_ptr nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318443</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 04 Jul 2007 18:03:03 GMT</pubDate></item></channel></rss>