<?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[Eine Frage zu Propertys: operator= überladen]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>nehmen wir an ich habe eine Klasse CPerson.</p>
<pre><code class="language-cpp">//Wie kann ich aus diesem Source:
CPerson oPerson;
oPerson.Vorname(&quot;Albert&quot;);
oPerson.Nachname(&quot;Bommel&quot;);

// Dieses machen?
CPerson oPerson;
oPerson.Vorname = &quot;Albert&quot;;
oPerson.Nachname = &quot;Bommel&quot;;

//Wie kriege ich hier heraus welche Property zugewiesen werden muß?
CPerson operator=(std::string s) {
}
</code></pre>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/189201/eine-frage-zu-propertys-operator-überladen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 07:37:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/189201.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Aug 2007 15:14:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 15:14:15 GMT]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>nehmen wir an ich habe eine Klasse CPerson.</p>
<pre><code class="language-cpp">//Wie kann ich aus diesem Source:
CPerson oPerson;
oPerson.Vorname(&quot;Albert&quot;);
oPerson.Nachname(&quot;Bommel&quot;);

// Dieses machen?
CPerson oPerson;
oPerson.Vorname = &quot;Albert&quot;;
oPerson.Nachname = &quot;Bommel&quot;;

//Wie kriege ich hier heraus welche Property zugewiesen werden muß?
CPerson operator=(std::string s) {
}
</code></pre>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341649</guid><dc:creator><![CDATA[martinsalo]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 15:21:23 GMT]]></title><description><![CDATA[<p>c++ kennt keine properties, aber du kannst es nachbauen: <a href="http://www.codeproject.com/cpp/cppproperties.asp" rel="nofollow">http://www.codeproject.com/cpp/cppproperties.asp</a><br />
<a href="http://www.codeguru.com/cpp/cpp/algorithms/general/article.php/c13039/" rel="nofollow">http://www.codeguru.com/cpp/cpp/algorithms/general/article.php/c13039/</a><br />
<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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341655</guid><dc:creator><![CDATA[Undertaker]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:21:23 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 15:45:24 GMT]]></title><description><![CDATA[<p>Vielen Dank, ich schaue es mir an <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341700</guid><dc:creator><![CDATA[martinsalo]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:45:24 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 15:46:40 GMT]]></title><description><![CDATA[<p>martinsalo schrieb:</p>
<blockquote>
<p>Hallo Forum,</p>
<p>nehmen wir an ich habe eine Klasse CPerson.</p>
<pre><code class="language-cpp">//Wie kann ich aus diesem Source:
CPerson oPerson;
oPerson.Vorname(&quot;Albert&quot;);
oPerson.Nachname(&quot;Bommel&quot;);

// Dieses machen?
CPerson oPerson;
oPerson.Vorname = &quot;Albert&quot;;
oPerson.Nachname = &quot;Bommel&quot;;

}
</code></pre>
</blockquote>
<p>Vorausgesetzt, Vorname und Nachname sind public member von CPerson und von einem Typ, der const char*- kompatibel ist (z.B. std::string), dann brauchst du garnichts weiter machen. Dann weist du naemlich einer string-membervariablen einfach einen String zu und gut ists.</p>
<p>martinsalo schrieb:</p>
<blockquote>
<pre><code class="language-cpp">//Wie kriege ich hier heraus welche Property zugewiesen werden muß?
CPerson operator=(std::string s)
</code></pre>
</blockquote>
<p>Das hier ist ueberhauptnicht moeglich, da es einen unaeren operator= nicht gibt. Was du vermutlich meinst ist etwas wie</p>
<pre><code class="language-cpp">//golbale Ueberladung
CPerson&amp; operator=(CPerson&amp; lhs, const std::string&amp; rhs);
//oder als klassenmember:
CPerson&amp; CPerson::operator=(const std::string&amp; rhs);
</code></pre>
<p>Das wuerde dann dazu dienen, einer Person einen String zuzuweisen. Was du mit dem String dann machst sei dahingestellt. Bsp:</p>
<pre><code class="language-cpp">CPerson&amp; CPerson::operator=(const std::string&amp; rhs)
{
  std::istringstream fullname(rhs);
  fullname &gt;&gt; this-&gt;Vorname &gt;&gt; this-&gt;Nachname;
  return *this;
}
</code></pre>
<p>(jetzt mal ohne Fehlerbehandlung)<br />
Damit ginge sowas wie</p>
<pre><code class="language-cpp">CPerson oPerson;
oPerson = &quot;Rainer Zufall&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1341702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341702</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:46:40 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 15:57:33 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Das hier ist ueberhauptnicht moeglich, da es einen unaeren operator= nicht gibt.</p>
</blockquote>
<p>Im Gegeinteil, es gibt keinen binären operator= (und damit auch keinen Nichtmember-operator=).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341711</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:57:33 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 16:28:33 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>Im Gegeinteil, es gibt keinen binären operator= (und damit auch keinen Nichtmember-operator=).</p>
</blockquote>
<p>Es gibt keinen unären operator=!</p>
<p>Deshalb muss die Methode operator= auch genau einen Parameter haben.</p>
<p>Außerdem hat das eine mit dem anderen nichts zu tun. Ich kann den binären operator+<br />
sowohl sowohl als Methode (mit einem Argument) als auch als globale Funktion (mit zwei Argumenten) implementieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341729</guid><dc:creator><![CDATA[Paul Panther]]></dc:creator><pubDate>Thu, 09 Aug 2007 16:28:33 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 18:58:41 GMT]]></title><description><![CDATA[<p>Paul Panther schrieb:</p>
<blockquote>
<p>Es gibt keinen unären operator=!</p>
</blockquote>
<p>Sagte ich, ja.</p>
<blockquote>
<p>Außerdem hat das eine mit dem anderen nichts zu tun. Ich kann den binären operator+<br />
sowohl sowohl als Methode (mit einem Argument) als auch als globale Funktion (mit zwei Argumenten) implementieren.</p>
</blockquote>
<p>Aber nicht den operator=.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341815</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 09 Aug 2007 18:58:41 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 20:08:03 GMT]]></title><description><![CDATA[<p>LordJaxom  schrieb:</p>
<blockquote>
<p>Sagte ich, ja.</p>
</blockquote>
<p>Hmmm, ich lese aber immer noch bei deinem post, dass es <strong>keinen</strong> binären operator= gäbe, was schlichtweg falsch ist.</p>
<p>LordJaxom  schrieb:</p>
<blockquote>
<p>Aber nicht den operator=.</p>
</blockquote>
<p>Ja, aber das hat imho nichts damit zu tun, ob der operator binär oder unär ist, und somit ist die Schlussfolgerung falsch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341859</guid><dc:creator><![CDATA[Paul Panther]]></dc:creator><pubDate>Thu, 09 Aug 2007 20:08:03 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 20:28:01 GMT]]></title><description><![CDATA[<p>Wo ich das lese, frage ich mich was mich da vorhin geritten hat. Der Operator ist natürlich binär, die Funktion operator= kann aber nur eine nichtstatische Membunktion sein. Sorry.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341864</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 09 Aug 2007 20:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 20:33:23 GMT]]></title><description><![CDATA[<p>Ok, dann hat sich das ja aufgeklärt. <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>Hatte mich schon gewundert, dass du geschrieben hattest:</p>
<p>LordJaxom schrieb:</p>
<blockquote>
<p>Sagte ich, ja.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1341866</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341866</guid><dc:creator><![CDATA[Paul Panther]]></dc:creator><pubDate>Thu, 09 Aug 2007 20:33:23 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Frage zu Propertys: operator= überladen on Thu, 09 Aug 2007 21:43:11 GMT]]></title><description><![CDATA[<p>Sry war mir entfallen dass op= nicht global möglich ist</p>
<p>Kopf-&gt;Tisch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341916</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 09 Aug 2007 21:43:11 GMT</pubDate></item></channel></rss>