<?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[operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;typename T&gt;
class base {
protected:
	T b;
	friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
	virtual void print(std::ostream&amp; os) const;
public:
	void set(int s) { b = s; };
	void a(const base&amp; c) { b = c.b; };
	int get() { return b; };
};

template&lt;typename T&gt;
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs) {
	bs.print(os);
	return os;
};

template&lt;typename T&gt;
void base&lt;T&gt;::print(std::ostream&amp; os) const {
	os &lt;&lt; this-&gt;b;
};

class derived: public base&lt;int&gt; {
public:
	derived() {};
	derived(int d) { this-&gt;b = d; };
};

int main() {
	derived b, e;
	e.set(100);
	b.a(e);
	std::cout &lt;&lt; e &lt;&lt; std::endl;
	std::cout &lt;&lt; b &lt;&lt; std::endl;
	system(&quot;pause&quot;);
}
</code></pre>
<p>hier bekomme ich link fehler 2001</p>
<blockquote>
<p>Error 1 error LNK2001: unresolved external symbol &quot;class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp; __cdecl operator&lt;&lt;(class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp;,class base&lt;int&gt; const &amp;)&quot; (??6@YAAAV?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi><mi>a</mi><mi>s</mi><mi>i</mi><mi>c</mi><mi mathvariant="normal">_</mi><mi>o</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>e</mi><mi>a</mi><mi>m</mi><mi mathvariant="normal">@</mi><mi>D</mi><mi>U</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">basic\_ostream@DU?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit">b</span><span class="mord mathit">a</span><span class="mord mathit">s</span><span class="mord mathit">i</span><span class="mord mathit">c</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">o</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">e</span><span class="mord mathit">a</span><span class="mord mathit">m</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mord mathit" style="margin-right:0.10903em;">U</span><span class="mclose">?</span></span></span></span>char_traits@D@std@@@std@@AAV01@ABV?$base@H@@@Z) main.obj Testcode</p>
</blockquote>
<p>noch eine Frage, hab irgendwo gelesen, dass konstruktoren und zuweisungsoperator nicht automatische vererbt werden, is das korrekt? bitte um bestaetigung, danke sehr</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/250505/operator-lt-lt-amp-gt-gt-in-template-klasse</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 20:53:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/250505.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Sep 2009 04:55:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 04:55:10 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;typename T&gt;
class base {
protected:
	T b;
	friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
	virtual void print(std::ostream&amp; os) const;
public:
	void set(int s) { b = s; };
	void a(const base&amp; c) { b = c.b; };
	int get() { return b; };
};

template&lt;typename T&gt;
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs) {
	bs.print(os);
	return os;
};

template&lt;typename T&gt;
void base&lt;T&gt;::print(std::ostream&amp; os) const {
	os &lt;&lt; this-&gt;b;
};

class derived: public base&lt;int&gt; {
public:
	derived() {};
	derived(int d) { this-&gt;b = d; };
};

int main() {
	derived b, e;
	e.set(100);
	b.a(e);
	std::cout &lt;&lt; e &lt;&lt; std::endl;
	std::cout &lt;&lt; b &lt;&lt; std::endl;
	system(&quot;pause&quot;);
}
</code></pre>
<p>hier bekomme ich link fehler 2001</p>
<blockquote>
<p>Error 1 error LNK2001: unresolved external symbol &quot;class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp; __cdecl operator&lt;&lt;(class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp;,class base&lt;int&gt; const &amp;)&quot; (??6@YAAAV?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi><mi>a</mi><mi>s</mi><mi>i</mi><mi>c</mi><mi mathvariant="normal">_</mi><mi>o</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>e</mi><mi>a</mi><mi>m</mi><mi mathvariant="normal">@</mi><mi>D</mi><mi>U</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">basic\_ostream@DU?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit">b</span><span class="mord mathit">a</span><span class="mord mathit">s</span><span class="mord mathit">i</span><span class="mord mathit">c</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">o</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">e</span><span class="mord mathit">a</span><span class="mord mathit">m</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mord mathit" style="margin-right:0.10903em;">U</span><span class="mclose">?</span></span></span></span>char_traits@D@std@@@std@@AAV01@ABV?$base@H@@@Z) main.obj Testcode</p>
</blockquote>
<p>noch eine Frage, hab irgendwo gelesen, dass konstruktoren und zuweisungsoperator nicht automatische vererbt werden, is das korrekt? bitte um bestaetigung, danke sehr</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1781330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781330</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Sat, 19 Sep 2009 04:55:10 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 04:56:44 GMT]]></title><description><![CDATA[<p>Konstruktoren, Destruktoren, Zuweisungsoperatoren, und friends werden nicht vererbt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1781331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781331</guid><dc:creator><![CDATA[DeepCopy]]></dc:creator><pubDate>Sat, 19 Sep 2009 04:56:44 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 12:16:52 GMT]]></title><description><![CDATA[<p>hab eben so geaendert trotz bekomme ich link fehler.</p>
<pre><code class="language-cpp">int main() {
    base&lt;int&gt; b, e;
    e.set(100);
    b.a(e);
    std::cout &lt;&lt; e &lt;&lt; std::endl;
    std::cout &lt;&lt; b &lt;&lt; std::endl;
    system(&quot;pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1781400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781400</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Sat, 19 Sep 2009 12:16:52 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 12:20:05 GMT]]></title><description><![CDATA[<p><code>protected</code> ist nach aussen, wie <code>private</code> . Du musst die Schnittstellte <code>public</code> machen. Sonst ist die Funktion nicht erreichbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1781401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781401</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sat, 19 Sep 2009 12:20:05 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 12:30:26 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
</code></pre>
<p>Das deklariert bei dir eine einzige Funktion. Das ist keine Templatefunktion.</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs) {
    bs.print(os);
    return os;
};
</code></pre>
<p>Hier definierst du eine Templatefunktion. Die hat nichts mit der ersten zu tun. Mögliche Lösungen: Definition schon in die Klasse schreiben, oder friend weglassen und die print-Funktion öffentlich zugänglich machen, oder</p>
<pre><code class="language-cpp">template&lt;typename U&gt;
friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;U&gt;&amp; bs);
</code></pre>
<p>In der Klasse schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1781402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781402</guid><dc:creator><![CDATA[Ryuzaki]]></dc:creator><pubDate>Sat, 19 Sep 2009 12:30:26 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 14:39:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;typename T&gt;  
class IOStreamOut;  

template&lt;typename T&gt;  
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const IOStreamOut&lt;T&gt;&amp; obj)
{
    std::string buffer = obj.Get().ToString();
    os.write( buffer.c_str(), static_cast&lt;std::streamsize&gt;(buffer.size()) );
    return os;
}

template&lt;typename T&gt;
class IOStreamOut 
{
public:

    /*
    * C'tor
    */
    IOStreamOut( const T&amp; obj )
        : m_obj( obj )
    {
    }

    /*
     * D'tor
     */
    virtual ~IOStreamOut(){};

    /*
     * ostream operator
     */
    friend std::ostream &amp;operator&lt;&lt; &lt;&gt;(std::ostream &amp;, const IOStreamOut&lt;T&gt;&amp; obj);  

    /*
     * Get the wrapped object
     */
    T Get() const
    {
        return m_obj;
    }

private:

    /*
     * C'tor
     *
     * Default constructor should never be called.
     */
    IOStreamOut(){};

    /*
     * The wrapped object
     */
    T m_obj;

};
</code></pre>
<p>hier is die gute loesung<br />
danke trotzdem eure hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1781440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781440</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Sat, 19 Sep 2009 14:39:54 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Sat, 19 Sep 2009 15:39:38 GMT]]></title><description><![CDATA[<p>ohne den rest gesehen zu haben:</p>
<pre><code class="language-cpp">os.write( buffer.c_str(), static_cast&lt;std::streamsize&gt;(buffer.size()) );
</code></pre>
<p>Oo</p>
<pre><code class="language-cpp">os &lt;&lt; buffer;
</code></pre>
<p>ist wohl zu einfach?</p>
<p>und das hier zu kurz?</p>
<pre><code class="language-cpp">template&lt;typename T&gt;  
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const IOStreamOut&lt;T&gt;&amp; obj)
{
    return os &lt;&lt; obj.Get().ToString();
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1781470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1781470</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 19 Sep 2009 15:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Thu, 24 Sep 2009 03:21:23 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;typename T&gt; class base;
template&lt;typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
template&lt;typename T&gt; std::ostream&amp; operator&gt;&gt;(std::istream&amp; is, base&lt;T&gt;&amp; bs);
class derived;

template&lt;typename T&gt;
class base {
protected:
    T b;
    friend std::ostream&amp; operator&lt;&lt; &lt;&gt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
    friend std::ostream&amp; operator&lt;&lt; &lt;&gt;(std::istream&amp; is, base&lt;T&gt;&amp; bs);
    virtual void print(std::ostream&amp; os) const;
    virtual void getinput(std::istream&amp; is);
public:
    void set(int s) { b = s; };
    void a(const base&amp; c) { b = c.b; };
    int get() { return b; };
};

template&lt;typename T&gt;
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs) {
    bs.print(os);
    return os;
};

template&lt;typename T&gt;
std::ostream&amp; operator&lt;&lt;(std::istream&amp; is, base&lt;T&gt;&amp; bs) {
    bs.getinput(is);
    return is;
};

template&lt;typename T&gt;
void base&lt;T&gt;::print(std::ostream&amp; os) const {
    os &lt;&lt; this-&gt;b;
};

template&lt;typename T&gt;
void base&lt;T&gt;::print(std::istream&amp; is) {
    os &gt;&gt; this-&gt;b;
};

int main() {
    base&lt;char&gt; b = 'A';
    std::cout &lt;&lt; e &lt;&lt; std::endl;
    std::cout &lt;&lt; b &lt;&lt; std::endl;
    system(&quot;pause&quot;);
}
</code></pre>
<p>also ich hab ausprobiert, bei Zahlentypen, ab unsigned short bis long long, funktioniert operator&gt;&gt; ohne problem, also base&lt;WORD&gt;, base&lt;int&gt;, base&lt;long&gt; kein problem, nur bei base&lt;char&gt; und base&lt;wchar_t&gt; weigert er die kompiliertarbeit, folgende fehler spuck es aus</p>
<blockquote>
<p>Error 2 error C2679: binary '&gt;&gt;' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) Testcode</p>
</blockquote>
<p>wie aendere ich es, dass es funktioniert, hab kein idee momentan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1783362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1783362</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Thu, 24 Sep 2009 03:21:23 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Thu, 24 Sep 2009 04:31:23 GMT]]></title><description><![CDATA[<p>Du hast da ein paar schräge Fehler, vermutlich Copy&amp;Paste. Schau nochmal genau alle op&lt;&lt;/&gt;&gt; und i/ostream an <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/1783366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1783366</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 24 Sep 2009 04:31:23 GMT</pubDate></item><item><title><![CDATA[Reply to operator&amp;lt;&amp;lt; &amp;amp; &amp;gt;&amp;gt; in template klasse on Thu, 24 Sep 2009 15:19:40 GMT]]></title><description><![CDATA[<p>KasF schrieb:</p>
<blockquote>
<p>Du hast da ein paar schräge Fehler, vermutlich Copy&amp;Paste. Schau nochmal genau alle op&lt;&lt;/&gt;&gt; und i/ostream an <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>
</blockquote>
<p>jo, hast recht, hier nun ohne copy fehler, kompilierfehler immer noch das selbe</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
template&lt;typename T&gt; class base;
template&lt;typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
template&lt;typename T&gt; std::istream&amp; operator&gt;&gt;(std::istream&amp; is, base&lt;T&gt;&amp; bs);

template&lt;typename T&gt;
class base {
protected:
	T b;
	friend std::ostream&amp; operator&lt;&lt; &lt;&gt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs);
	friend std::istream&amp; operator&gt;&gt; &lt;&gt;(std::istream&amp; is, base&lt;T&gt;&amp; bs);
	virtual void print(std::ostream&amp; os) const;
public:
	base(const T&amp; a): b(a) {};
	void set(int s) { b = s; };
	void a(const base&amp; c) { b = c.b; };
	int get() { return b; };
};

template&lt;typename T&gt;
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const base&lt;T&gt;&amp; bs) {
	os &lt;&lt; bs.b;
	return os;
};

template&lt;typename T&gt;
std::istream&amp; operator&gt;&gt;(std::istream&amp; is, base&lt;T&gt;&amp; bs) {
	is &gt;&gt; bs;
        return is;
}

template&lt;typename T&gt;
void base&lt;T&gt;::print(std::ostream&amp; os) const {
	os &lt;&lt; this-&gt;b;
};

class derived: public base&lt;char&gt; {
public:
	derived(char d):base(d) {  };
};

int main() {
	base&lt;char&gt; b = 'A';
	std::cin &gt;&gt; b &gt;&gt; std::endl;
	std::cout &lt;&lt; b &lt;&lt; std::endl;
	system(&quot;pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1783672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1783672</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Thu, 24 Sep 2009 15:19:40 GMT</pubDate></item></channel></rss>