<?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[Funktioniert ein delete this]]></title><description><![CDATA[<p>Ich hab eine Klasse die nur dynamisch erzeugt werden kann, also mit new.<br />
Jetzt soll diese Klasse irgendwann natürlich wieder gelöscht werden, funktioniert es wenn ich der Klasse sage das sie sich löschen soll und sie sich dann selber mit delete this löscht?<br />
Also so ungefähr.</p>
<pre><code>class IchLöschMichSelber{
      ...
public:
    void NunLöschIchMich(){
         delete this;
    };
    ...
};

int main(){
  IchLöschMichSelber* ILMS = new IchLöschMichSelber;

  //Ist das folgende gleichbedeutend mit &quot;delete ILMS&quot;?
  ILMS-&gt;NunLöschIchMich();

  return 0;
};
</code></pre>
<p>Solange ich immer NunLöschIchMich() aufrufe müsste es doch eigentlich funktionieren, oder?</p>
<p>Viele Grüße floorball</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/314205/funktioniert-ein-delete-this</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 09:48:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/314205.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Feb 2013 14:38:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktioniert ein delete this on Sat, 23 Feb 2013 14:38:07 GMT]]></title><description><![CDATA[<p>Ich hab eine Klasse die nur dynamisch erzeugt werden kann, also mit new.<br />
Jetzt soll diese Klasse irgendwann natürlich wieder gelöscht werden, funktioniert es wenn ich der Klasse sage das sie sich löschen soll und sie sich dann selber mit delete this löscht?<br />
Also so ungefähr.</p>
<pre><code>class IchLöschMichSelber{
      ...
public:
    void NunLöschIchMich(){
         delete this;
    };
    ...
};

int main(){
  IchLöschMichSelber* ILMS = new IchLöschMichSelber;

  //Ist das folgende gleichbedeutend mit &quot;delete ILMS&quot;?
  ILMS-&gt;NunLöschIchMich();

  return 0;
};
</code></pre>
<p>Solange ich immer NunLöschIchMich() aufrufe müsste es doch eigentlich funktionieren, oder?</p>
<p>Viele Grüße floorball</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2301364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2301364</guid><dc:creator><![CDATA[floorball]]></dc:creator><pubDate>Sat, 23 Feb 2013 14:38:07 GMT</pubDate></item><item><title><![CDATA[Reply to Funktioniert ein delete this on Sat, 23 Feb 2013 14:46:04 GMT]]></title><description><![CDATA[<p>Ja, es &quot;funktioniert&quot;, solange danach garantiert auf keine Member mehr zugegriffen wird.<br />
Eine gute Idee ist das aber selten bis nie.</p>
<p>Edit: dazu gibt es auch einen FAQ-Eintrag:<br />
<a href="http://www.parashift.com/c++-faq-lite/delete-this.html" rel="nofollow">http://www.parashift.com/c++-faq-lite/delete-this.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2301368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2301368</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Sat, 23 Feb 2013 14:46:04 GMT</pubDate></item><item><title><![CDATA[Reply to Funktioniert ein delete this on Sat, 23 Feb 2013 14:50:01 GMT]]></title><description><![CDATA[<p>danke für die antwort</p>
<blockquote>
<p>Eine gute Idee ist das aber selten bis nie.</p>
</blockquote>
<p>So richtig zufrieden bin ich damit auch nicht, werd wohl mal nach einer anderen Lösung suchen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2301370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2301370</guid><dc:creator><![CDATA[floorball]]></dc:creator><pubDate>Sat, 23 Feb 2013 14:50:01 GMT</pubDate></item></channel></rss>