<?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[Frage zu Strings]]></title><description><![CDATA[<p>Also ich habe eine frage. Und zwar was ist schneller?</p>
<pre><code class="language-cpp">std::string name = &quot;Synonym&quot;;
std::string name(&quot;Synonym&quot;);
</code></pre>
<p>oder gibt es keinen unterschied in der geschwindigkeit?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/307508/frage-zu-strings</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 18:01:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307508.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Aug 2012 16:10:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu Strings on Tue, 28 Aug 2012 16:10:06 GMT]]></title><description><![CDATA[<p>Also ich habe eine frage. Und zwar was ist schneller?</p>
<pre><code class="language-cpp">std::string name = &quot;Synonym&quot;;
std::string name(&quot;Synonym&quot;);
</code></pre>
<p>oder gibt es keinen unterschied in der geschwindigkeit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246383</guid><dc:creator><![CDATA[Synonym]]></dc:creator><pubDate>Tue, 28 Aug 2012 16:10:06 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Tue, 28 Aug 2012 16:12:17 GMT]]></title><description><![CDATA[<p>Das ist beides identisch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246385</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 28 Aug 2012 16:12:17 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Tue, 28 Aug 2012 16:13:58 GMT]]></title><description><![CDATA[<p>Praktisch kein Unterschied. Dazu habe ich auch erst gestern etwas geschrieben:</p>
<p>Gugelmoser schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;

struct MyInt
{
	int x;

    MyInt(int const y): x( y )
    {
		std::cout &lt;&lt; &quot;Constructor 1 called.&quot; &lt;&lt; std::endl;
	}
	
	MyInt(MyInt const &amp;y): x( y.x )
    {
		std::cout &lt;&lt; &quot;Constructor 2 called.&quot; &lt;&lt; std::endl;
	}
};

int main()
{
	/*
		So, what's going on there? In fact it is not that complicated:

			1) A instance, named 'i', shall be created.

			2) The right operand of the assignment operator is a literal of type 'int', thus your struct 'MyInt' must have a constructor looking like 'MyInt(int)'.

			3) Well done, your struct 'MyInt' does have a constructor looking like 'MyInt(int)', thus the compiler is happy.

			4)
				a) The constructor 'MyInt(int)' is called, creating a temporary. ( like 'MyInt tmp(1);' )
			
				In theory:
					b) That created temporary serves as argument for the copy constructor 'MyInt(MyInt const&amp;)'.
					c) The copy constructor receives that temporary.
					d) The copy constructor is now capable of initializing the actual instance 'i' with the aid of that temporary.
					--&gt; Finally two instances were created, the temporary and 'i'.
						--&gt; And to be more precise, that two instances are equivalent.
							--&gt; Kinda stupid and absolutely unnecessary, isn't it?

				In practice:
					b) The copy constructor 'MyInt(MyInt const&amp;)' is not called. The constructor 'MyInt(int)' is the only constructor being called.
					c) As a consequence, the instance created by 'MyInt(int)' is no temporary but the actual instance 'i'.
					--&gt; Finally only one instance was created, namely 'i'.
						--&gt; That's pretty cool, isn't it?
							--&gt; NOTE: The theoretical process must be feasible (compilable), otherwise the practical process can't be done.
										What I'm trying to say is, you will get a compiler error, if the copy constructor is not public.
	*/
    MyInt i = 1;
}
</code></pre>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2246387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246387</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 28 Aug 2012 16:13:58 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Wed, 29 Aug 2012 12:20:47 GMT]]></title><description><![CDATA[<p>Synonym schrieb:</p>
<blockquote>
<p>Also ich habe eine frage. Und zwar was ist schneller?</p>
<pre><code class="language-cpp">std::string name = &quot;Synonym&quot;;
std::string name(&quot;Synonym&quot;);
</code></pre>
<p>oder gibt es keinen unterschied in der geschwindigkeit?</p>
</blockquote>
<p>Das eine ist copy-initialisation, das andere direct-initialisation (Klammerinitialisierung). Die erste Variante unterscheidet sich nur dadurch von der zweiten, dass sie erfordert, dass ein (nicht expliziter) Ctor von <code>std::string</code> vorhanden ist, der einen C-String entgegennimmt - was selbstverständlich der Fall ist.</p>
<p>Ansonsten sind sie Geschmackssache.</p>
<p>Edit: <strong>So spät!?</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246388</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 29 Aug 2012 12:20:47 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Wed, 29 Aug 2012 10:26:15 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Die erste Variante unterscheidet sich nur dadurch von der zweiten, dass sie erfordert, dass ein Copy-Ctor von <code>std::string</code> vorhanden ist.</p>
</blockquote>
<p>Ist das nicht eigentlich eher ein nicht expliziter Konvertierungskonstruktor, der da vorhanden sein muss?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246603</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 29 Aug 2012 10:26:15 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Wed, 29 Aug 2012 11:33:00 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Das eine ist copy-initialisation, das andere normale Initialisierung.</p>
</blockquote>
<p>Wenn du schon hier schon für das erste den Begriff aus dem C++ Standard verwendest, kannst du das für die zweite Initialisierung auch tun: direct-initialization. <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>Sone schrieb:</p>
<blockquote>
<p>Die erste Variante unterscheidet sich nur dadurch von der zweiten, dass sie erfordert, dass ein Copy-Ctor von <code>std::string</code> vorhanden ist.</p>
</blockquote>
<p>Sie erfordert auch, dass der Konstruktor, der den const char* entgegen nimmt, nicht mit <code>explicit</code> markiert wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246634</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 29 Aug 2012 11:33:00 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Wed, 29 Aug 2012 11:36:24 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>...</p>
</blockquote>
<p>Hat es 'nen Grund, dass Du noch mal schreibst, was schon geschrieben wurde?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246635</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 29 Aug 2012 11:36:24 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Wed, 29 Aug 2012 12:18:24 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>Die erste Variante unterscheidet sich nur dadurch von der zweiten, dass sie erfordert, dass ein Copy-Ctor von <code>std::string</code> vorhanden ist.</p>
</blockquote>
<p>Ist das nicht eigentlich eher ein nicht expliziter Konvertierungskonstruktor, der da vorhanden sein muss?</p>
</blockquote>
<p>Natürlich, ich hab mich total verheddert. Editiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246659</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 29 Aug 2012 12:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Strings on Wed, 29 Aug 2012 13:53:26 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>krümelkacker schrieb:</p>
<blockquote>
<p>...</p>
</blockquote>
<p>Hat es 'nen Grund, dass Du noch mal schreibst, was schon geschrieben wurde?</p>
</blockquote>
<p>Absicht ist es jedenfalls nicht. Hab das wohl übersehen, dass du schon &quot;explicit&quot; erwähnt hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246700</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 29 Aug 2012 13:53:26 GMT</pubDate></item></channel></rss>