<?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[[Erledigt] Zuweisung, Swap String]]></title><description><![CDATA[<p>Hi ich hab grad folgendes Problem</p>
<p>Ich hab eine Klasse mit einem String als Member, und muss den Zuweisungsoperator implementieren.</p>
<pre><code class="language-cpp">class material
{
public:
	material() {}
	material( std::string name_ ) : name( name_ ) {}
	~material(void) {}
	material&amp; operator=( const material&amp; other )
	{
		if( &amp;other != this ) {
			std::swap( name, other.name );
		}
		return *this;
	}

	std::string name;
};
</code></pre>
<p>Wenn ich das so wie oben mache gibt das diesen Fehler.</p>
<pre><code class="language-cpp">...material.h(14) : error C2664: 'void std::swap&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;_Ty&gt;&gt;(std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;,std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;)'
   : cannot convert parameter 2 from 'const std::string' to 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;'
        with
        [
            _Ty=char,
            _Elem=char,
            _Traits=std::char_traits&lt;char&gt;,
            _Ax=std::allocator&lt;char&gt;
        ]
        and
        [
            _Elem=char,
            _Traits=std::char_traits&lt;char&gt;,
            _Ax=std::allocator&lt;char&gt;
        ]
        Conversion loses qualifiers
</code></pre>
<p>Und wenn ich nur</p>
<pre><code class="language-cpp">name = other.name
</code></pre>
<p>schreibe, hab ich undefiniertes Verhalten, sprich einen BadPtr was zur Exception führt</p>
<blockquote>
<p>material {name=&quot;ìû&quot; }</p>
</blockquote>
<p>Wer kann mir helfen?<br />
Danke im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/147052/erledigt-zuweisung-swap-string</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 22:38:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/147052.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 13 May 2006 12:01:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Erledigt] Zuweisung, Swap String on Sat, 13 May 2006 12:28:28 GMT]]></title><description><![CDATA[<p>Hi ich hab grad folgendes Problem</p>
<p>Ich hab eine Klasse mit einem String als Member, und muss den Zuweisungsoperator implementieren.</p>
<pre><code class="language-cpp">class material
{
public:
	material() {}
	material( std::string name_ ) : name( name_ ) {}
	~material(void) {}
	material&amp; operator=( const material&amp; other )
	{
		if( &amp;other != this ) {
			std::swap( name, other.name );
		}
		return *this;
	}

	std::string name;
};
</code></pre>
<p>Wenn ich das so wie oben mache gibt das diesen Fehler.</p>
<pre><code class="language-cpp">...material.h(14) : error C2664: 'void std::swap&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;_Ty&gt;&gt;(std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;,std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;)'
   : cannot convert parameter 2 from 'const std::string' to 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; &amp;'
        with
        [
            _Ty=char,
            _Elem=char,
            _Traits=std::char_traits&lt;char&gt;,
            _Ax=std::allocator&lt;char&gt;
        ]
        and
        [
            _Elem=char,
            _Traits=std::char_traits&lt;char&gt;,
            _Ax=std::allocator&lt;char&gt;
        ]
        Conversion loses qualifiers
</code></pre>
<p>Und wenn ich nur</p>
<pre><code class="language-cpp">name = other.name
</code></pre>
<p>schreibe, hab ich undefiniertes Verhalten, sprich einen BadPtr was zur Exception führt</p>
<blockquote>
<p>material {name=&quot;ìû&quot; }</p>
</blockquote>
<p>Wer kann mir helfen?<br />
Danke im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1057007</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1057007</guid><dc:creator><![CDATA[THX 1138]]></dc:creator><pubDate>Sat, 13 May 2006 12:28:28 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Zuweisung, Swap String on Sat, 13 May 2006 12:29:17 GMT]]></title><description><![CDATA[<p>Easy <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
hat sich erledigt, der Fehler lag woanders.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1057016</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1057016</guid><dc:creator><![CDATA[THX 1138]]></dc:creator><pubDate>Sat, 13 May 2006 12:29:17 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Zuweisung, Swap String on Sat, 13 May 2006 12:39:50 GMT]]></title><description><![CDATA[<blockquote>
<p>und muss den Zuweisungsoperator implementieren.</p>
</blockquote>
<p>glaub ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1057022</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1057022</guid><dc:creator><![CDATA[glaub]]></dc:creator><pubDate>Sat, 13 May 2006 12:39:50 GMT</pubDate></item></channel></rss>