<?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[Automatisches generieren von Konstruktoren]]></title><description><![CDATA[<p>Hallo @all</p>
<p>Ich habe folgendes Problem mit der Generierung von Konstruktoren vom Compiler:</p>
<pre><code>class A
{
public:
	A()
	{
		a = &quot;Hallo&quot;;
		b = &quot; &quot;;
		c = &quot;Welt&quot;;
	}

	A( const A&amp; ) = default;
	A( A&amp;&amp; ) = default;

	string a,b,c;
};
</code></pre>
<p>mit dem Schlüsselwort default, soll es dem Compiler möglich sein, einfache Kopier-Konstruktoren oder Move-Konstruktoren zu bauen. Beim Copy-Ctor funktioniert die Sache auch ziemlich gut, jedoch meckert er beim Move-Ctor rum.<br />
Fehlermeldung:</p>
<blockquote>
<p>'A::A(A &amp;&amp;)' : is not a special member function which can be defaulted</p>
</blockquote>
<p>Ist es demnach nur möglich Kopier-Konstruktoren automatisch erstellen zu lassen?</p>
<p>Dies ist ein vereinfachtes Beispiel um mein Problem zu verdeutlichen.</p>
<p>Ich habe außerdem noch eine zweite &quot;kleine&quot; Frage:<br />
Wenn ich Parameter als rvalue übergeben möchte, habe ich das bisher immer so gemacht:</p>
<pre><code>void f( string&amp;&amp; str )
{
	mystr = std::forward&lt;string&gt;( str );
}
</code></pre>
<p>Ich habe letzens eine 2. Version gesehen:</p>
<pre><code>void f( string str )
{
    mystr = std::move( str );
}
</code></pre>
<p>Ich persönlich finde die obere Variante besser (und auch richtiger) aber vllt übersehe ich etwas, weshalb die zweite Variante doch besser sein könnte.</p>
<p>Danke und MfG</p>
<p>Hlymur</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332449/automatisches-generieren-von-konstruktoren</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 20:41:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332449.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 May 2015 13:48:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 13:48:03 GMT]]></title><description><![CDATA[<p>Hallo @all</p>
<p>Ich habe folgendes Problem mit der Generierung von Konstruktoren vom Compiler:</p>
<pre><code>class A
{
public:
	A()
	{
		a = &quot;Hallo&quot;;
		b = &quot; &quot;;
		c = &quot;Welt&quot;;
	}

	A( const A&amp; ) = default;
	A( A&amp;&amp; ) = default;

	string a,b,c;
};
</code></pre>
<p>mit dem Schlüsselwort default, soll es dem Compiler möglich sein, einfache Kopier-Konstruktoren oder Move-Konstruktoren zu bauen. Beim Copy-Ctor funktioniert die Sache auch ziemlich gut, jedoch meckert er beim Move-Ctor rum.<br />
Fehlermeldung:</p>
<blockquote>
<p>'A::A(A &amp;&amp;)' : is not a special member function which can be defaulted</p>
</blockquote>
<p>Ist es demnach nur möglich Kopier-Konstruktoren automatisch erstellen zu lassen?</p>
<p>Dies ist ein vereinfachtes Beispiel um mein Problem zu verdeutlichen.</p>
<p>Ich habe außerdem noch eine zweite &quot;kleine&quot; Frage:<br />
Wenn ich Parameter als rvalue übergeben möchte, habe ich das bisher immer so gemacht:</p>
<pre><code>void f( string&amp;&amp; str )
{
	mystr = std::forward&lt;string&gt;( str );
}
</code></pre>
<p>Ich habe letzens eine 2. Version gesehen:</p>
<pre><code>void f( string str )
{
    mystr = std::move( str );
}
</code></pre>
<p>Ich persönlich finde die obere Variante besser (und auch richtiger) aber vllt übersehe ich etwas, weshalb die zweite Variante doch besser sein könnte.</p>
<p>Danke und MfG</p>
<p>Hlymur</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452210</guid><dc:creator><![CDATA[Hlymur]]></dc:creator><pubDate>Fri, 01 May 2015 13:48:03 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 15:20:01 GMT]]></title><description><![CDATA[<p>std::forward vs std::move:</p>
<p>Siehe mal folgendes Beispiel:</p>
<pre><code>template &lt;typename T&gt;
void func(T&amp;&amp; param) {
    otherFunc(std::forward&lt;T&gt;(param));
}
</code></pre>
<p>Durch type deduction und reference collapsing kann T&amp;&amp; hier T&amp;&amp; (wenn ein rvalue übergeben wurde) und T const&amp; (wenn ein lvalue übergeben wurde) sein.<br />
std::move würde nun beides egal was es ist zu einer rvalue-ref casten. std::forward macht das nicht, es leitet genau das weiter (lvalue / rvalue).<br />
In einem nicht template Kontext ist std::forward also (meines wissens) fehl am Platz.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452222</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 01 May 2015 15:20:01 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 15:47:55 GMT]]></title><description><![CDATA[<p>Wenn der Compiler VS2013 ist, kann er Movekonstruktoren noch nicht richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452224</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452224</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 01 May 2015 15:47:55 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 16:18:30 GMT]]></title><description><![CDATA[<blockquote>
<p>Durch type deduction und reference collapsing kann T&amp;&amp; hier T&amp;&amp; (wenn ein rvalue übergeben wurde) und T const&amp; (wenn ein lvalue übergeben wurde) sein.</p>
</blockquote>
<p>.. und <code>T&amp;</code> und <code>T const&amp;&amp;</code> .</p>
<blockquote>
<p>std::move würde nun beides egal was es ist zu einer rvalue-ref casten.</p>
</blockquote>
<p>Wobei angemerkt werden sollte dass <code>T const&amp;</code> zu <code>T const&amp;&amp;</code> wird, was (praktisch) niemals Kandidat für Move-Konstruktoren ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452225</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 01 May 2015 16:18:30 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 17:28:51 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Durch type deduction und reference collapsing kann T&amp;&amp; hier T&amp;&amp; (wenn ein rvalue übergeben wurde) und T const&amp; (wenn ein lvalue übergeben wurde) sein.</p>
</blockquote>
<p>.. und <code>T&amp;</code> und <code>T const&amp;&amp;</code> .</p>
</blockquote>
<p>wann denn T&amp;?<br />
(Ich seh schon, ich bereu die Frage gleich und hau mir die Hand vor den Kopf... Vielleicht aber auch nicht :))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452228</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 01 May 2015 17:28:51 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 18:05:01 GMT]]></title><description><![CDATA[<p>5cript schrieb:</p>
<blockquote>
<p>wann denn T&amp;?</p>
</blockquote>
<p>Das ist doch Scheißegal. Denk einfach daran, dass das eine forwarding reference ist, und Argumente mit ihr und <code>forward</code> <strong>exakt so weitergegeben werden wie sie ankommen</strong>. Sie <code>const</code> weiterzugeben, wo sie eigentlich modifizierbar sind, wäre falsch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452231</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 01 May 2015 18:05:01 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 18:10:04 GMT]]></title><description><![CDATA[<p>5cript schrieb:</p>
<blockquote>
<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Durch type deduction und reference collapsing kann T&amp;&amp; hier T&amp;&amp; (wenn ein rvalue übergeben wurde) und T const&amp; (wenn ein lvalue übergeben wurde) sein.</p>
</blockquote>
<p>.. und <code>T&amp;</code> und <code>T const&amp;&amp;</code> .</p>
</blockquote>
<p>wann denn T&amp;?</p>
</blockquote>
<p>Na, immer wenn ein nicht konstantes LValue übergeben wird.<br />
<a href="http://ideone.com/C8lfkC" rel="nofollow">http://ideone.com/C8lfkC</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2452232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452232</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Fri, 01 May 2015 18:10:04 GMT</pubDate></item><item><title><![CDATA[Reply to Automatisches generieren von Konstruktoren on Fri, 01 May 2015 20:18:27 GMT]]></title><description><![CDATA[<p>Also zum Thema Move-Ctor:<br />
Mit VS 2013 geht es nicht, aber grundsätzlich schon? ok, dann hoffe ich auf VS 2015 oder GCC</p>
<p>Zum zweiten Theme:<br />
Wenn ich nun einfach z.B. einen String <strong>verschieben</strong> möchte.<br />
Dann als Parameter std::string oder std::string&amp;&amp;, aber aufjedenfall kein std::forward sondern std::move?</p>
<pre><code>void func(std::string oder std::string&amp;&amp; str)
{
    mystr = std::move(str);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2452245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2452245</guid><dc:creator><![CDATA[Hlymur]]></dc:creator><pubDate>Fri, 01 May 2015 20:18:27 GMT</pubDate></item></channel></rss>