<?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[this-Referenz an Basis-Objekt]]></title><description><![CDATA[<p>Hallo,</p>
<p>ist folgender Code als kritisch einzustufen oder kann man so etwas gefahrenlos<br />
machen?</p>
<pre><code class="language-cpp">MyObject::MyObject() : MyBaseObject(*this){
}
</code></pre>
<p>Das Objekt ist ja noch nicht vollständig erzeugt.</p>
<p>Gruß,<br />
Mark</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/284173/this-referenz-an-basis-objekt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 05:30:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/284173.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 27 Mar 2011 12:06:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Sun, 27 Mar 2011 12:06:05 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ist folgender Code als kritisch einzustufen oder kann man so etwas gefahrenlos<br />
machen?</p>
<pre><code class="language-cpp">MyObject::MyObject() : MyBaseObject(*this){
}
</code></pre>
<p>Das Objekt ist ja noch nicht vollständig erzeugt.</p>
<p>Gruß,<br />
Mark</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2040785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2040785</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Sun, 27 Mar 2011 12:06:05 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 05:19:25 GMT]]></title><description><![CDATA[<p>Wozu soll das gut sein? Du hättest eine Referenz auf sich selbst. *this ist das aktuelle Objekt, egal ob Du es in seiner Eigenschaft als MyObjekt oder als BaseObjekt ansprichst.<br />
Vielleicht ist Namensgebung schon ein wenig irreführend, evtl. wäre</p>
<p>MyClass und BaseClass</p>
<p>besser.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2041091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041091</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 28 Mar 2011 05:19:25 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 06:08:02 GMT]]></title><description><![CDATA[<p>Belli schrieb:</p>
<blockquote>
<p>Wozu soll das gut sein?</p>
</blockquote>
<p>Als Beispiel:<br />
Stell dir vor du hast ein Objekt mit</p>
<pre><code class="language-cpp">void operator&lt;&lt;(char c);
</code></pre>
<p>Jetzt kann du eine Basis-Klasse schreiben, die ihn auf mehrere Typen erweitert.<br />
Diese möchtest du jetzt in deinem Objekt verfügbar machen.<br />
Dann erbst du davon und übergibst eine Referenz auf this und es kann alle anderen<br />
Typen ebenfalls...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2041103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041103</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Mon, 28 Mar 2011 06:08:02 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 06:42:43 GMT]]></title><description><![CDATA[<p>Ähhh ... die abgeleiteten Klassen erben auch so die überladenen Operatoren:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

class base
{
	public:
		void operator&lt;&lt; (char c){str.push_back(c);}
		void operator&lt;&lt; (int i){_i = i;}

		string str;
		int _i;
};

class derived : public base
{
};

int main()
{
	derived obj;

	obj &lt;&lt; 'a';
	obj &lt;&lt; 'Z';

	obj &lt;&lt; 13;

	cout &lt;&lt; obj.str &lt;&lt; endl;
	cout &lt;&lt; obj._i;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2041106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041106</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 28 Mar 2011 06:42:43 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 08:27:10 GMT]]></title><description><![CDATA[<p>davon mal abgesehen wird doch der copy ctor aufgerufen oder?<br />
weil man ja quasi ein objekt einer klasse an die eigene klasse gibt, ob das nun ein derivat oder nicht ist, sollte doch egal sein...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2041145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041145</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 28 Mar 2011 08:27:10 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 08:38:09 GMT]]></title><description><![CDATA[<p>Nicht an die eigene Klasse, an das eigene Objekt, also an sich selbst.<br />
Aber als welchen Typ soll man die entsprechende Variable in der Basisklasse überhaupt vereinbaren?<br />
Bleibt eigentlich nur der Typ der Basisklasse selbst, denn die weiß ja nicht, welche Klassen irgendwann mal von ihr ableiten - und dann sieht man noch deutlicher, dass man eine Referenz auf sich selbst hat. Die hat man mittels this aber sowieso immer, also das macht imo keinen Sinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2041151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041151</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 28 Mar 2011 08:38:09 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 10:31:34 GMT]]></title><description><![CDATA[<p>Ich meinte das etwa so:</p>
<pre><code class="language-cpp">class Stream{
    virtual void operator&lt;&lt;(char i)=0;
};

class DataStream{
public:
    DataStream(Stream&amp; s) : stream(s){
    }

    void operator&lt;&lt;(int i){
        for(int j=0; j&lt;sizeof(int); ++j){
             stream &lt;&lt; static_cast&lt;char*&gt;(&amp;i)[j];
        }
    } 

private:
    Stream&amp; stream;
}; 

class SpecificStreamA : public DataStream, public Stream{
public:
    SpecificStreamA() : DataStream(*this){
    }
    virtual void operator&lt;&lt;(char i)=0{...}
}; 

class SpecificStreamB : public DataStream, public Stream{
public:
    SpecificStreamB() : DataStream(*this){
    }
    virtual void operator&lt;&lt;(char i)=0{...}
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2041211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041211</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Mon, 28 Mar 2011 10:31:34 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 10:33:25 GMT]]></title><description><![CDATA[<p>Ach ich bin dähmlich...</p>
<p>Dann kann ich auch dir pure virtual Funktion direkt in DataStream packen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2041212</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041212</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Mon, 28 Mar 2011 10:33:25 GMT</pubDate></item><item><title><![CDATA[Reply to this-Referenz an Basis-Objekt on Mon, 28 Mar 2011 11:47:09 GMT]]></title><description><![CDATA[<p>Mark81 schrieb:</p>
<blockquote>
<p>Ach ich bin dähmlich...</p>
</blockquote>
<p>Ach, wie die Dahme?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2041246</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2041246</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Mon, 28 Mar 2011 11:47:09 GMT</pubDate></item></channel></rss>