<?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[Ist das hier falsche Benutzung eines shared_ptr?]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe zu diesem Code eine Frage:</p>
<pre><code class="language-cpp">Foo* f = new Foo(&quot;MyFoo&quot;);
shared_ptr&lt;Foo&gt; p1(f);
int c = p1.use_count(); // 1

shared_ptr&lt;Foo&gt;p2(f);
c = p1.use_count(); // 1
c = p2.use_count(); // 1
</code></pre>
<p>Das ist eine falsche Benutzung eines shared_ptr, oder?<br />
Wenn p1 und p2 aus dem Scope gehen, wird ja zwei mal versucht f zu löschen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290317/ist-das-hier-falsche-benutzung-eines-shared_ptr</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 15:10:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290317.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 24 Jul 2011 09:43:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 09:43:10 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe zu diesem Code eine Frage:</p>
<pre><code class="language-cpp">Foo* f = new Foo(&quot;MyFoo&quot;);
shared_ptr&lt;Foo&gt; p1(f);
int c = p1.use_count(); // 1

shared_ptr&lt;Foo&gt;p2(f);
c = p1.use_count(); // 1
c = p2.use_count(); // 1
</code></pre>
<p>Das ist eine falsche Benutzung eines shared_ptr, oder?<br />
Wenn p1 und p2 aus dem Scope gehen, wird ja zwei mal versucht f zu löschen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097064</guid><dc:creator><![CDATA[Smarter?]]></dc:creator><pubDate>Sun, 24 Jul 2011 09:43:10 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 09:47:22 GMT]]></title><description><![CDATA[<p>ja ist es.</p>
<p>der shared_ptr zählt mit wie viele zeiger auf ein heap objekt zeigen und der letzte shared_ptr der zerstört wird räumt hinter sich auf.<br />
das funktioniert aber nur wenn du den shared_ptr an einen anderen übergibst und nicht mit rohen zeigern arbeitest</p>
<p>initialisier den ersten shared_ptr direkt mit new Foo() und übergib diesens hared_ptr an alle weiteren shared_ptr die du nutzt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097066</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 24 Jul 2011 09:47:22 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 09:48:31 GMT]]></title><description><![CDATA[<p>Ja, das ist falsch, weil weder p1 noch p2 wissen, daß noch ein anderer shared_ptr auf ihre Daten zeigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097067</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sun, 24 Jul 2011 09:48:31 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:20:54 GMT]]></title><description><![CDATA[<p>Wobei es möglich ist einen Smartpointer zu implementieren, der hier korrekt freigibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097073</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:20:54 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:22:13 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Wobei es möglich ist einen Smartpointer zu implementieren, der hier korrekt freigibt.</p>
</blockquote>
<p>aber nicht sinnvoll</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097074</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097074</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:22:13 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:25:44 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>aber nicht sinnvoll</p>
</blockquote>
<p>Ich halte Smartpointer allgemein nicht für sinnvoll. Ein einzelnes Objekt brauch ich nicht auf dem Heap zu erzeugen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097075</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:25:44 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:29:09 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>aber nicht sinnvoll</p>
</blockquote>
<p>Ich halte Smartpointer allgemein nicht für sinnvoll. Ein einzelnes Objekt brauch ich nicht auf dem Heap zu erzeugen.</p>
</blockquote>
<p>wtf?</p>
<p>Warum haeltst du Smartpointer nicht fuer sinnvoll? Ohne Smartpointer kein RAII und ohne RAII kein guter Code...</p>
<p>Ob ein Objekt auf dem Heap erzeugt werden muss hat auch nichts mit der Anzahl der Objekte zu tun...</p>
<p>Mein Punkt war aber: einen Smartpointer zu schreiben der hier korrekt freigibt waere dumm. Zumindest faellt mir keine Situation ein wo er Sinn machen wuerden oder effizient waere.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097077</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:29:09 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:29:12 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>aber nicht sinnvoll</p>
</blockquote>
<p>Ich halte Smartpointer allgemein nicht für sinnvoll. Ein einzelnes Objekt brauch ich nicht auf dem Heap zu erzeugen.</p>
</blockquote>
<p>fail</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097078</guid><dc:creator><![CDATA[rolleis]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:29:12 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:31:07 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>warum haeltst du Smartpointer nicht fuer sinnvoll? Ohne Smartpointer kein RAII und ohne RAII kein guter Code...</p>
</blockquote>
<p>Einzelne Objekte erzeuge ich auf dem Stack. Verstehe ich dich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097079</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:33:22 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>warum haeltst du Smartpointer nicht fuer sinnvoll? Ohne Smartpointer kein RAII und ohne RAII kein guter Code...</p>
</blockquote>
<p>Einzelne Objekte erzeuge ich auf dem Stack. Verstehe ich dich falsch?</p>
</blockquote>
<p>Die Anzahl der Objekte die du brauchst hat idR nichts mit Stack/Heap zu tun. Es sei denn sie wuerden nicht auf den Stack passen... Die Entscheidung ob Stack oder Heap faellt anhand der Lebenserwartung des Objektes.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097080</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097080</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:33:22 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 10:33:44 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>warum haeltst du Smartpointer nicht fuer sinnvoll? Ohne Smartpointer kein RAII und ohne RAII kein guter Code...</p>
</blockquote>
<p>Einzelne Objekte erzeuge ich auf dem Stack. Verstehe ich dich falsch?</p>
</blockquote>
<p>Und wie machst du das dann beim Einsatz der Polymorphie?</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097081</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Sun, 24 Jul 2011 10:33:44 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:14:42 GMT]]></title><description><![CDATA[<p>Vielleicht so?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class A
{
public:
	virtual void hello_world() { std::cout &lt;&lt; &quot;A: Hello World!&quot; &lt;&lt; std::endl; }
};

class B : public A
{
public:
	virtual void hello_world() { std::cout &lt;&lt; &quot;B: Hello World!&quot; &lt;&lt; std::endl; }
};

int main(int argc, char *argv[])
{
	A&amp;&amp; my_object = B();
	my_object.hello_world();
}
</code></pre>
<p><a href="http://ideone.com/GKWIp" rel="nofollow">http://ideone.com/GKWIp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097089</guid><dc:creator><![CDATA[life]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:14:42 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:07:31 GMT]]></title><description><![CDATA[<p>Wieso geht Polymorphie stackwise nicht?</p>
<pre><code class="language-cpp">class X
{
public:
virtual void foo() {std::cout &lt;&lt; &quot;Hallo&quot;;}
};

class Y : public X
{
public:
virtual void foo() {std::cout &lt;&lt; &quot;Halloooo!!&quot;;}
};

void callIt(X&amp; ref)
{
    ref.foo();
}

int main()
{
    Y y;
    callIt(y);
}
</code></pre>
<p>Edit: Wieso R-Value-Referenz? Eine ganz normale tut doch auch oder wird bei nem auf dem Stack erstellten Objekt nicht zwangsläufig ne Vtable erstellt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097091</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:07:31 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:10:25 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Edit: Wieso R-Value-Referenz? Eine ganz normale tut doch auch oder wird bei nem auf dem Stack erstellten Objekt nicht zwangsläufig ne Vtable erstellt?</p>
</blockquote>
<p>Ich wollte nur den blöden Fehler wegen der non-const Referenz auf ein rvalue wegbekommen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097094</guid><dc:creator><![CDATA[life]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:10:25 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:22:16 GMT]]></title><description><![CDATA[<p>Man merkt deutlich, dass EOutOfResources noch im &quot;Hello World&quot; Bereich ist und noch nie was größeres geschrieben hat. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097097</guid><dc:creator><![CDATA[MitleserROT]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:22:16 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:25:14 GMT]]></title><description><![CDATA[<p>MitleserROT schrieb:</p>
<blockquote>
<p>Man merkt deutlich, dass EOutOfResources noch im &quot;Hello World&quot; Bereich ist und noch nie was größeres geschrieben hat. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Kann ich nicht bestätigen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
<p>EDIT: Ich nutze generell keine Smartpointer und das kann euch doch egal sein. Ihc hatte deswegen nie Probleme.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097098</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:25:14 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:25:16 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>MitleserROT schrieb:</p>
<blockquote>
<p>Man merkt deutlich, dass EOutOfResources noch im &quot;Hello World&quot; Bereich ist und noch nie was größeres geschrieben hat. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Kann ich nicht bestätigen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
</blockquote>
<p>Dann erklaer mal deine Aussage bzgl Stack/Heap.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097100</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:25:16 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:26:58 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>MitleserROT schrieb:</p>
<blockquote>
<p>Man merkt deutlich, dass EOutOfResources noch im &quot;Hello World&quot; Bereich ist und noch nie was größeres geschrieben hat. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Kann ich nicht bestätigen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
</blockquote>
<p>Was hast du denn schon größeres geschrieben? von RAII hältst du dann wohl auch nicht so viel, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097101</guid><dc:creator><![CDATA[Nachfrager]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:26:58 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:27:04 GMT]]></title><description><![CDATA[<p>Smarter? schrieb:</p>
<blockquote>
<p>Hi!</p>
<p>Ich habe zu diesem Code eine Frage:</p>
<pre><code class="language-cpp">Foo* f = new Foo(&quot;MyFoo&quot;);
shared_ptr&lt;Foo&gt; p1(f);
int c = p1.use_count(); // 1

shared_ptr&lt;Foo&gt;p2(f);
c = p1.use_count(); // 1
c = p2.use_count(); // 1
</code></pre>
<p>Das ist eine falsche Benutzung eines shared_ptr, oder?<br />
Wenn p1 und p2 aus dem Scope gehen, wird ja zwei mal versucht f zu löschen, oder?</p>
</blockquote>
<p>Ich vermute mal du hast nur einen Pointer als Parameter, aber du möchtest eigentlich an den shared_ptr, der diesen enthält?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;boost/enable_shared_from_this.hpp&gt;

class Foo : public boost::enable_shared_from_this&lt;Foo&gt;{
};

int main(){
        Foo* f = new Foo();
        boost::shared_ptr&lt;Foo&gt; p1(f);
        int c = p1.use_count(); // 1 
        std::cout &lt;&lt; c &lt;&lt; std::endl;
        boost::shared_ptr&lt;Foo&gt;p2(f-&gt;shared_from_this());
        c = p1.use_count(); // 2 
        std::cout &lt;&lt; c &lt;&lt; std::endl;

}
</code></pre>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097102</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:27:04 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:28:47 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Dann erklaer mal deine Aussage bzgl Stack/Heap.</p>
</blockquote>
<p>Ich verstehe nicht, was es daran auszusetzen gibt, dass ich das Objekt auf dem Stack statt über einen Smartpointer auf dem Heap anlege.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097103</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:28:47 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:29:43 GMT]]></title><description><![CDATA[<p>Nachfrager schrieb:</p>
<blockquote>
<p>von RAII hältst du dann wohl auch nicht so viel, oder?</p>
</blockquote>
<p>Eigentlich doch....<br />
Wieso änderst du deinen Namen bei jedem Post?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097104</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:29:43 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:34:11 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Dann erklaer mal deine Aussage bzgl Stack/Heap.</p>
</blockquote>
<p>Ich verstehe nicht, was es daran auszusetzen gibt, dass ich das Objekt auf dem Stack statt über einen Smartpointer auf dem Heap anlege.</p>
</blockquote>
<p>Weil es beim Verlassen des Scopes zerstört wird und man halt 'manchmal' Objekte hat, die länger leben sollen...</p>
<p>EDIT: Ich hoffe er verwendet hier nur Smart-Pointer wegen Code-Reduktion... Zumal er noch threadsafe 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>
]]></description><link>https://www.c-plusplus.net/forum/post/2097106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097106</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:34:11 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:34:13 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Dann erklaer mal deine Aussage bzgl Stack/Heap.</p>
</blockquote>
<p>Ich verstehe nicht, was es daran auszusetzen gibt, dass ich das Objekt auf dem Stack statt über einen Smartpointer auf dem Heap anlege.</p>
</blockquote>
<p>Und Nachts ist es kaelter als draussen.</p>
<p>Wenn du etwas auf den Stack anlegen kannst - dann bedeutet dies, dass du die Lebenszeit des Objektes nicht dynamisch festlegst sondern statisch. Es bedeutet, dass dieses Objekt eine genau definierte, statische, Lebensdauer hat.</p>
<p>Hier verwendet man nie Smartpointer. Es wuerde keinen Sinn machen.</p>
<p>Wenn aber die Lebensdauer dynamisch sein muss, dann muss man das Objekt per new oder aehnlichem anlegen und genau dann sind Smartpointer erstmal erste Wahl.</p>
<p>Und genau das verwirrt hier. Denn Stack Objekte mit Smartpointern vergleichen ist dumm. Das deutet daraufhin dass du etwas grundlegendes nicht verstanden hast. Deshalb die Frage ob du es erklaeren kannst.</p>
<p>PS:<br />
einzeilige Posts zeigen auch nicht wirklich von viel interesse etwas sinnvolles zu dieser diskussion beizutragen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097108</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:34:13 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:36:26 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Es bedeutet, dass dieses Objekt eine genau definierte, <s>statische</s> automatische, Lebensdauer hat.</p>
</blockquote>
<p>Ich hätte nicht gemeckert, wenn da ein anderes Wort als statisch stehen würde, aber statische Lebensdauer ist etwas anderes (auch wenn ich annehme, dass du das weisst). <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097110</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:36:26 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:37:20 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Es bedeutet, dass dieses Objekt eine genau definierte, <s>statische</s> automatische, Lebensdauer hat.</p>
</blockquote>
<p>Ich hätte nicht gemeckert, wenn da ein anderes Wort als statisch stehen würde, aber statische Lebensdauer ist etwas anderes (auch wenn ich annehme, dass du das weisst). <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Statisch im Sinne von Starr (gegenteil von dynamisch). Nicht static.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097111</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das hier falsche Benutzung eines shared_ptr? on Sun, 24 Jul 2011 11:53:39 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>Dann erklaer mal deine Aussage bzgl Stack/Heap.</p>
</blockquote>
<p>Ich verstehe nicht, was es daran auszusetzen gibt, dass ich das Objekt auf dem Stack statt über einen Smartpointer auf dem Heap anlege.</p>
</blockquote>
<p>Das eine hat doch nichts mit dem anderen zu tun.<br />
Wie willst du denn einen dynamischen Baum mit Knoten aufbauen, wenn du nur den Stack benutzt? So ein Schwachsinn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097117</guid><dc:creator><![CDATA[Omgg]]></dc:creator><pubDate>Sun, 24 Jul 2011 11:53:39 GMT</pubDate></item></channel></rss>