<?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[Template: Set-Funktion hat keinen Effekt auf Referenz]]></title><description><![CDATA[<p>Also, ich hab ein Template, welches eine Referenz beinhaltet,<br />
und auch eine SetFunktion für diese.</p>
<p>Und da wird eine Zuweisung einfach ignoriert. Ich kanns nachprüfen,<br />
sie findet offensichtlich nicht statt:</p>
<pre><code class="language-cpp">#ifndef guest_h
#define guest_h
#include &lt;iostream&gt;
namespace CMOUTPUT
{

template&lt;class T&gt;
class guest
{
protected:
	T&amp; output_obj;
public:
	guest(T&amp; t);
	virtual ~guest();
	guest(const guest&lt;T&gt;&amp; copy);
	guest&lt;T&gt;&amp; operator=(const guest&lt;T&gt;&amp; copy);
	T&amp; Getoutput_obj();
	void Setoutput_obj(T&amp; Output_obj){output_obj = Output_obj;std::cout &lt;&lt; &quot;SETOUTPUT&quot; &lt;&lt; Output_obj.Getname() &lt;&lt; &quot; &quot; &lt;&lt; Getoutput_obj().Getname() &lt;&lt; std::endl;}
};

#include &quot;guest.hpp&quot;

template&lt;class T&gt;
guest&lt;T&gt;::guest(T&amp; t):output_obj(t)
{

}

template&lt;class T&gt;
guest&lt;T&gt;::~guest()
{

}

template&lt;class T&gt;
guest&lt;T&gt;::guest(const guest&lt;T&gt;&amp; copy):output_obj(copy.output_obj)
{

}

template&lt;class T&gt;
guest&lt;T&gt;&amp; guest&lt;T&gt;::operator=(const guest&lt;T&gt;&amp; copy)
{
	output_obj = copy.output_obj;
	return *this;
}

template&lt;class T&gt;
T&amp; guest&lt;T&gt;::Getoutput_obj()
{
	return output_obj;
}

/*template&lt;class T&gt;
void guest&lt;T&gt;::Setoutput_obj(T&amp; Output_obj)
{
	output_obj=Output_obj;
	std::cout &lt;&lt; &quot;SETOUTPUT&quot; &lt;&lt; Output_obj.Getname() &lt;&lt; &quot; &quot; &lt;&lt; output_obj.Getname() &lt;&lt; std::endl;//ergibt &quot;SETOUTPUTende begin&quot;
}*/

}
#endif
</code></pre>
<p>Von diesem Template leite ich dann Klassen entsprechend ab.<br />
Dort wird Setoutput_obj aufgerufen, und offensichtlich die Zuweisung<br />
ignoriert. Anders kann ich mir das nicht erklären...</p>
<p>Jemand eine Idee ?</p>
<p>phlox</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/124796/template-set-funktion-hat-keinen-effekt-auf-referenz</link><generator>RSS for Node</generator><lastBuildDate>Mon, 24 Aug 2026 02:35:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/124796.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 31 Oct 2005 15:45:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 15:45:14 GMT]]></title><description><![CDATA[<p>Also, ich hab ein Template, welches eine Referenz beinhaltet,<br />
und auch eine SetFunktion für diese.</p>
<p>Und da wird eine Zuweisung einfach ignoriert. Ich kanns nachprüfen,<br />
sie findet offensichtlich nicht statt:</p>
<pre><code class="language-cpp">#ifndef guest_h
#define guest_h
#include &lt;iostream&gt;
namespace CMOUTPUT
{

template&lt;class T&gt;
class guest
{
protected:
	T&amp; output_obj;
public:
	guest(T&amp; t);
	virtual ~guest();
	guest(const guest&lt;T&gt;&amp; copy);
	guest&lt;T&gt;&amp; operator=(const guest&lt;T&gt;&amp; copy);
	T&amp; Getoutput_obj();
	void Setoutput_obj(T&amp; Output_obj){output_obj = Output_obj;std::cout &lt;&lt; &quot;SETOUTPUT&quot; &lt;&lt; Output_obj.Getname() &lt;&lt; &quot; &quot; &lt;&lt; Getoutput_obj().Getname() &lt;&lt; std::endl;}
};

#include &quot;guest.hpp&quot;

template&lt;class T&gt;
guest&lt;T&gt;::guest(T&amp; t):output_obj(t)
{

}

template&lt;class T&gt;
guest&lt;T&gt;::~guest()
{

}

template&lt;class T&gt;
guest&lt;T&gt;::guest(const guest&lt;T&gt;&amp; copy):output_obj(copy.output_obj)
{

}

template&lt;class T&gt;
guest&lt;T&gt;&amp; guest&lt;T&gt;::operator=(const guest&lt;T&gt;&amp; copy)
{
	output_obj = copy.output_obj;
	return *this;
}

template&lt;class T&gt;
T&amp; guest&lt;T&gt;::Getoutput_obj()
{
	return output_obj;
}

/*template&lt;class T&gt;
void guest&lt;T&gt;::Setoutput_obj(T&amp; Output_obj)
{
	output_obj=Output_obj;
	std::cout &lt;&lt; &quot;SETOUTPUT&quot; &lt;&lt; Output_obj.Getname() &lt;&lt; &quot; &quot; &lt;&lt; output_obj.Getname() &lt;&lt; std::endl;//ergibt &quot;SETOUTPUTende begin&quot;
}*/

}
#endif
</code></pre>
<p>Von diesem Template leite ich dann Klassen entsprechend ab.<br />
Dort wird Setoutput_obj aufgerufen, und offensichtlich die Zuweisung<br />
ignoriert. Anders kann ich mir das nicht erklären...</p>
<p>Jemand eine Idee ?</p>
<p>phlox</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904682</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Mon, 31 Oct 2005 15:45:14 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 16:32:26 GMT]]></title><description><![CDATA[<p>Naja das kommt wohl auf den Zuweisungsoperator von T an, denn der wird ja aufgerufen. Poste den doch mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904755</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Mon, 31 Oct 2005 16:32:26 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 16:35:46 GMT]]></title><description><![CDATA[<p>7H3 N4C3R schrieb:</p>
<blockquote>
<p>Naja das kommt wohl auf den Zuweisungsoperator von T an, denn der wird ja aufgerufen. Poste den doch mal.</p>
</blockquote>
<p>ähm, das ist ne referenz... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /><br />
Der sollte da keine Rolle spielen. Oder doch ?</p>
<p>Vielleicht liegts auch daran, das heute Halloween ist, und es auf meinem PC spukt *muhaha*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904759</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Mon, 31 Oct 2005 16:35:46 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 16:43:05 GMT]]></title><description><![CDATA[<p>Ist das jetzt ein Halloween-Scherz? *gg*</p>
<p>Referenzen können nur initialisiert aber nicht zugewiesen werden.</p>
<p>Steht auf der linken Seite des Zuweisungsoperators eine Referenz, so wird die Zuweisung auf das Objekt durchgeführt, auf das die Referenz zeigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904770</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Mon, 31 Oct 2005 16:43:05 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:09:44 GMT]]></title><description><![CDATA[<p>7H3 N4C3R schrieb:</p>
<blockquote>
<p>Ist das jetzt ein Halloween-Scherz? *gg*</p>
<p>Referenzen können nur initialisiert aber nicht zugewiesen werden.</p>
<p>Steht auf der linken Seite des Zuweisungsoperators eine Referenz, so wird die Zuweisung auf das Objekt durchgeführt, auf das die Referenz zeigt.</p>
</blockquote>
<p>Nein, ist kein Scherz.<br />
Also, kann ich eine referenz garnicht zuweisen ?<br />
Das wäre mir aber neu <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/904798</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904798</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:09:44 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:18:01 GMT]]></title><description><![CDATA[<p>Was macht wohl ?</p>
<pre><code class="language-cpp">int x = 1;
int&amp; ref = x;
ref = 5;
</code></pre>
<p>Das erste = initialisiert die Referenz und das zweite gleich weisst dem x den Wert 5 zu (weil ref x referenziert).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904809</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904809</guid><dc:creator><![CDATA[niemand]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:18:01 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:35:21 GMT]]></title><description><![CDATA[<p>niemand schrieb:</p>
<blockquote>
<p>Was macht wohl ?</p>
<pre><code class="language-cpp">int x = 1;
int&amp; ref = x;
ref = 5;
</code></pre>
<p>Das erste = initialisiert die Referenz und das zweite gleich weisst dem x den Wert 5 zu (weil ref x referenziert).</p>
</blockquote>
<p>danke aber ich kenne Referenzen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /><br />
Das man sie (angeblich) aber nicht wieder neu zuweisen kann, ist mir neu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904835</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:35:21 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:39:14 GMT]]></title><description><![CDATA[<p>Eine Referenz bezieht sich Zeit ihres Lebens auf dieselbe Variable, zuweisungen an andere variablen kopieren nur deren Wert in die zugehörige Variable:</p>
<pre><code class="language-cpp">int a=3;
int b=5;
int&amp; ref=a; //ref bezieht sich jetzt immer auf a!!
ref = b; //weist ref (also damit a) den Wert von b zu =&gt; a = 5
         //verknüpft ref aber NICHT mit b!
ref = 7; // b ist also immernoch 5, a ist jetzt 7...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/904842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904842</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:39:14 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:39:56 GMT]]></title><description><![CDATA[<blockquote>
<p>Das man sie (angeblich) aber nicht wieder neu zuweisen kann, ist mir neu.</p>
</blockquote>
<p>Nix mit angeblich, mit Sicherheit kann man Referenzen nur initialisieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904844</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:39:56 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:40:04 GMT]]></title><description><![CDATA[<p>phlox81 schrieb:</p>
<blockquote>
<p>danke aber ich kenne Referenzen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Offensichtlich nicht. Eine Zuweisung an eine Referenz bewirkt eine Zuweisung an das Objekt, mit dem die Referenz initialisiert wurde. &quot;Umbiegen&quot; kannst du nur Zeiger.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904845</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:40:04 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 17:55:25 GMT]]></title><description><![CDATA[<p>Hier auch nochmal das Quote aus dem Standard (5.17, Clause 6):</p>
<p>When the left operand of an assignment operator denotes a reference to T, the operation assigns to the<br />
object of type T denoted by the reference.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904867</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Mon, 31 Oct 2005 17:55:25 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 20:32:56 GMT]]></title><description><![CDATA[<p>[quote=&quot;phlox81&quot;]</p>
<p>niemand schrieb:</p>
<blockquote>
<p>Was macht wohl ?<br />
danke aber ich kenne Referenzen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /><br />
Das man sie (angeblich) aber nicht wieder neu zuweisen kann, ist mir neu.</p>
</blockquote>
<p>Sorry, aber ich hatte genau angenommen, dass Du Referenzen im Prinzip kennst. Obiger Code sollte Dir nur vor Augen führen, dass eine Zuweisung auf eine Referenz eben den Inhalt der referenzierten Variable ändert. Hätte ich nicht angenommen, dass Dir das eigentlich klar, hätte ich es kommentiert <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>
]]></description><link>https://www.c-plusplus.net/forum/post/905059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/905059</guid><dc:creator><![CDATA[niemand]]></dc:creator><pubDate>Mon, 31 Oct 2005 20:32:56 GMT</pubDate></item><item><title><![CDATA[Reply to Template: Set-Funktion hat keinen Effekt auf Referenz on Mon, 31 Oct 2005 21:30:05 GMT]]></title><description><![CDATA[<p>phlox81 is'n troll...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/905234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/905234</guid><dc:creator><![CDATA[kenner...]]></dc:creator><pubDate>Mon, 31 Oct 2005 21:30:05 GMT</pubDate></item></channel></rss>