<?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[Fehler in g++ oder nicht standardkonformer Code?]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgender Code wird von g++ 3.x einwandfrei kompiliert:</p>
<pre><code class="language-cpp">template &lt;class Type&gt; class Foo
{
        private:
                Type m_t;

                Foo( const Foo&amp; ); // Zeile 6
        public:
                explicit Foo( const Type&amp; t )
                 : m_t(t)
                {
                }

                operator Type() const
                {
                        return m_t;
                }
};

template &lt;class A&gt; bool set( const A&amp; value )
{
        return true;
}

int main()
{
        int i = 5;
        Foo&lt;int&gt; foo(i);

        set( Foo&lt;int&gt;( (int)foo ) ); // Zeile 30
}
</code></pre>
<p>g++ 4.0 hingegen sagt:</p>
<pre><code>bla.cc: In function 'int main()':
bla.cc:6: error: 'Foo&lt;Type&gt;::Foo(const Foo&lt;Type&gt;&amp;) [with Type = int]' is private
bla.cc:30: error: within this context
</code></pre>
<p>Ist nun der g++ kaputt oder der Code?<br />
Kennt jemand einen Workaround außer eine lokale Variable zu definieren<br />
und diese dann der set Funktion als Parameter zu übergeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/122196/fehler-in-g-oder-nicht-standardkonformer-code</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 02:47:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/122196.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Oct 2005 17:53:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sat, 01 Oct 2005 17:53:18 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgender Code wird von g++ 3.x einwandfrei kompiliert:</p>
<pre><code class="language-cpp">template &lt;class Type&gt; class Foo
{
        private:
                Type m_t;

                Foo( const Foo&amp; ); // Zeile 6
        public:
                explicit Foo( const Type&amp; t )
                 : m_t(t)
                {
                }

                operator Type() const
                {
                        return m_t;
                }
};

template &lt;class A&gt; bool set( const A&amp; value )
{
        return true;
}

int main()
{
        int i = 5;
        Foo&lt;int&gt; foo(i);

        set( Foo&lt;int&gt;( (int)foo ) ); // Zeile 30
}
</code></pre>
<p>g++ 4.0 hingegen sagt:</p>
<pre><code>bla.cc: In function 'int main()':
bla.cc:6: error: 'Foo&lt;Type&gt;::Foo(const Foo&lt;Type&gt;&amp;) [with Type = int]' is private
bla.cc:30: error: within this context
</code></pre>
<p>Ist nun der g++ kaputt oder der Code?<br />
Kennt jemand einen Workaround außer eine lokale Variable zu definieren<br />
und diese dann der set Funktion als Parameter zu übergeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/884274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884274</guid><dc:creator><![CDATA[ign0rant]]></dc:creator><pubDate>Sat, 01 Oct 2005 17:53:18 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sat, 01 Oct 2005 18:25:22 GMT]]></title><description><![CDATA[<p>gcc 4.0 liegt wohl richtig<br />
Standard 12.2 sagt, dass ein temporäres Objekt benötigt wird um einen rvalue (in Deinem Fall das Foo&lt;int&gt;( (int)foo) an eine Referenz zu binden. Auch wenn dieses Objekt vom Compiler dann eliminiert werden kann, muss der Compiler prüfen, ob es angelegt werden kann. Und das geht in Deinem Fall nicht.</p>
<blockquote>
<p>Temporaries of class type are created in various contexts: binding an rvalue to a reference (8.5.3), returning an rvalue (6.6.3), a conversion that creates an rvalue (4.1, 5.2.9, 5.2.11, 5.4), throwing an exception (15.1), entering a handler (15.3), and in some initializations (8.5). [Note: the lifetime of exception objects is described in 15.1. ] Even when the creation of the temporary object is avoided (12.8), all the semantic restrictions must be respected as if the temporary object was created. [Example: even if the copy constructor is not called, all the semantic restrictions, such as accessibility (clause 11), shall be satisfied. ]<br />
2 [Example:</p>
<pre><code class="language-cpp">class X {
// ...
public:
// ...
  X(int);
  X(const X&amp;);
  ~X();
};

X f(X);

void g()
{
  X a(1);
  X b = f(X(2));
  a = f(a);
}
</code></pre>
<p>Here, an implementation might use a temporary in which to construct X(2) before passing it to f() using X’s copyconstructor;<br />
alternatively, X(2) might be constructed in the space used to hold the argument.<br />
Also, a temporary might be used to hold the result of f(X(2)) before copying it to b using X’s copyconstructor;<br />
alternatively, f()’s result might be constructed in b. On the other hand, the expression a=f(a) requires a temporary for either the argument a or the result of f(a) to avoid undesired aliasing of a]</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/884290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884290</guid><dc:creator><![CDATA[niemand]]></dc:creator><pubDate>Sat, 01 Oct 2005 18:25:22 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sat, 01 Oct 2005 18:25:53 GMT]]></title><description><![CDATA[<p>Comeau compiliert es auch nicht. Dein Code ist wohl falsch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/884291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884291</guid><dc:creator><![CDATA[standar1]]></dc:creator><pubDate>Sat, 01 Oct 2005 18:25:53 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sat, 01 Oct 2005 21:47:24 GMT]]></title><description><![CDATA[<p>eigentlich müsste der code einwandfrei funktionieren und auch mein vc++6 schluckt ihn ohne zu murren *seltsam*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/884371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884371</guid><dc:creator><![CDATA[Konfusius]]></dc:creator><pubDate>Sat, 01 Oct 2005 21:47:24 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sat, 01 Oct 2005 21:48:09 GMT]]></title><description><![CDATA[<p>Konfusius schrieb:</p>
<blockquote>
<p>eigentlich müsste der code einwandfrei funktionieren und auch mein vc++6 schluckt ihn ohne zu murren *seltsam*</p>
</blockquote>
<p><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="🤡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/884372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884372</guid><dc:creator><![CDATA[niemand|Klo]]></dc:creator><pubDate>Sat, 01 Oct 2005 21:48:09 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sun, 02 Oct 2005 06:49:02 GMT]]></title><description><![CDATA[<p>ign0rant schrieb:</p>
<blockquote>
<p>folgender Code wird von g++ 3.x einwandfrei kompiliert:</p>
</blockquote>
<p>Kann ich nicht bestätigen, zumindest beim 3.4.4.</p>
<p>Konfusius schrieb:</p>
<blockquote>
<p>eigentlich müsste der code einwandfrei funktionieren und auch mein vc++6 schluckt ihn ohne zu murren *seltsam*</p>
</blockquote>
<p>Nicht raten, nachschlagen...</p>
<p>ign0rant schrieb:</p>
<blockquote>
<p>Kennt jemand einen Workaround außer eine lokale Variable zu definieren</p>
</blockquote>
<p>Nunja, da dein Code keinen Sinn ergibt, kann ich dazu nicht viel sagen. Vielleicht könntest du mal ein reelles Szenario als Beispielcode posten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/884423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884423</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sun, 02 Oct 2005 06:49:02 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sun, 02 Oct 2005 07:14:17 GMT]]></title><description><![CDATA[<p>groovemaster schrieb:</p>
<blockquote>
<p>Konfusius schrieb:</p>
<blockquote>
<p>eigentlich müsste der code einwandfrei funktionieren und auch mein vc++6 schluckt ihn ohne zu murren *seltsam*</p>
</blockquote>
<p>Nicht raten, nachschlagen...</p>
</blockquote>
<p>nicht raten? ich dachte, es wäre mal ein perfekt getarnter witz <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/884425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884425</guid><dc:creator><![CDATA[elise]]></dc:creator><pubDate>Sun, 02 Oct 2005 07:14:17 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in g++ oder nicht standardkonformer Code? on Sun, 02 Oct 2005 15:29:55 GMT]]></title><description><![CDATA[<p>Wenn Konfusius statt dem &quot;und auch&quot; einfach ein Komma gemacht hätte, hätte ich ihn glatt durchgehen lassen. <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/884644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884644</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sun, 02 Oct 2005 15:29:55 GMT</pubDate></item></channel></rss>