<?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[boost-Warnung in ptr_vector: unref. lok. Var. res?]]></title><description><![CDATA[<p>Hi,</p>
<p>ich nutze gerade den ptr-Container und erhalte eine merkwürdige Warnung:</p>
<pre><code class="language-cpp">template&lt; class T &gt; // Code in der boost-lib, nicht von mir
    inline T* new_clone( const T&amp; r )
    {
        //
        // @remark: if you get a compile-error here,
        //          it is most likely because you did not
        //          define new_clone( const T&amp; ) in the namespace
        //          of T.
        //
        T* res = new T( r );
        BOOST_ASSERT( typeid(r) == typeid(*res) &amp;&amp;
                      &quot;Default new_clone() sliced object!&quot; );
        return res;
    }
</code></pre>
<p>Und er sagt beim return, res sei eine undefinierte lokale Variable. Wie habe ich das denn zu verstehen? Sieht doch nicht wirklich undefiniert aus. Sollte mir das zu denken geben?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/293391/boost-warnung-in-ptr_vector-unref-lok-var-res</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 08:12:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/293391.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 02 Oct 2011 09:12:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost-Warnung in ptr_vector: unref. lok. Var. res? on Sun, 02 Oct 2011 09:12:48 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich nutze gerade den ptr-Container und erhalte eine merkwürdige Warnung:</p>
<pre><code class="language-cpp">template&lt; class T &gt; // Code in der boost-lib, nicht von mir
    inline T* new_clone( const T&amp; r )
    {
        //
        // @remark: if you get a compile-error here,
        //          it is most likely because you did not
        //          define new_clone( const T&amp; ) in the namespace
        //          of T.
        //
        T* res = new T( r );
        BOOST_ASSERT( typeid(r) == typeid(*res) &amp;&amp;
                      &quot;Default new_clone() sliced object!&quot; );
        return res;
    }
</code></pre>
<p>Und er sagt beim return, res sei eine undefinierte lokale Variable. Wie habe ich das denn zu verstehen? Sieht doch nicht wirklich undefiniert aus. Sollte mir das zu denken geben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2126093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2126093</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 02 Oct 2011 09:12:48 GMT</pubDate></item><item><title><![CDATA[Reply to boost-Warnung in ptr_vector: unref. lok. Var. res? on Sun, 02 Oct 2011 09:40:38 GMT]]></title><description><![CDATA[<p>Kannst du mal die exakte, unübersetzte Fehlermeldung angeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2126106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2126106</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 02 Oct 2011 09:40:38 GMT</pubDate></item><item><title><![CDATA[Reply to boost-Warnung in ptr_vector: unref. lok. Var. res? on Sun, 02 Oct 2011 10:14:09 GMT]]></title><description><![CDATA[<p>Es ist nur eine Warnung, aber natürlich gern:</p>
<p>`</p>
<p>1&gt;  Application.cpp</p>
<p>1&gt;d:\entwicklungsbibliotheken\boost_1_44_0\boost\ptr_container\clone_allocator.hpp(37): warning C4700: Die nicht initialisierte lokale Variable &quot;res&quot; wurde verwendet.`</p>
<p>in der return-Zeile o.geposteten Codes.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2126120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2126120</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 02 Oct 2011 10:14:09 GMT</pubDate></item><item><title><![CDATA[Reply to boost-Warnung in ptr_vector: unref. lok. Var. res? on Sun, 02 Oct 2011 10:26:44 GMT]]></title><description><![CDATA[<p>Ahh, uninitialisiert! Ich war schon sehr verwirrt durch das undefiniert.</p>
<p>Allgemein haben Compiler natürlich Recht bei so etwas, aber ich sehe es gerade selber nicht. Kannst du ein kurzes Beispiel erstellen (von boost kannst du erwarten, dass wir das haben, aber die Version ist evtl. noch wichtig), welches die Warnung wirft. Und den Compiler, Compileroptionen und Compilerversion.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2126124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2126124</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 02 Oct 2011 10:26:44 GMT</pubDate></item><item><title><![CDATA[Reply to boost-Warnung in ptr_vector: unref. lok. Var. res? on Sun, 02 Oct 2011 10:34:33 GMT]]></title><description><![CDATA[<p>Ich habe mich damit nicht mit dem Klonen von ptr_containern auseinandergesetzt. Es sieht aber so aus, als ob dieses new_clone nur ein Fallback von Boost ist, welcher nur dann funktioniert, wenn keine Polymorphie im Spiel ist. Möchtest Du das Klonen polymorph haben, musst Du eine eigene new_clone-Funktion schreiben die dann per ADL aufgerufen werden soll. Beispiel:</p>
<pre><code class="language-cpp">class abc { // abstrakte basis-klasse
public:
  virtual ~abc() {}
  virtual abc* clone() const = 0;
};

inline abc* new_clone(abc const&amp; x) {return x.clone();}
</code></pre>
<p>So oder so ähnlich steht das bestimmt auch in der Doku.</p>
<p>Edit:<br />
Ach! Und ich dachte, Dir fliegt die Assertion um die Ohren... Nächtes mal bitte gleich die entsprechende Meldung verraten. Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2126129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2126129</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 02 Oct 2011 10:34:33 GMT</pubDate></item><item><title><![CDATA[Reply to boost-Warnung in ptr_vector: unref. lok. Var. res? on Sun, 02 Oct 2011 21:30:01 GMT]]></title><description><![CDATA[<p>Ja, sorry im Topic stand &quot;unref.&quot; und &quot;boost-Warnung&quot;, aber im OP war das verwirrend.</p>
<p>Kriege ich diese Warnung weg oder kann ich sie getrost ignorieren bzw. weg-präprozessor-ieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2126213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2126213</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 02 Oct 2011 21:30:01 GMT</pubDate></item></channel></rss>