<?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[Nicht aufgelöstes externes Symbol bei Template Funktion]]></title><description><![CDATA[<p>ich hab eine klasse erstellt um mit dem windows api konsolenausgaben durchzuführen, weil das mit cout nicht geht. die ausgabe und auch der überladene &lt;&lt; operator funktionieren, aber wenn ich beim operator templates benutzen will geht es nicht.<br />
zum schreiben in konsole hab ich diese funktion:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
void cout::write(T arg)
{
	ostringstream str; 
    str&lt;&lt;arg;
	  WriteConsole(hStdOut, str.str().c_str(),strlen(str.str().c_str()),&amp;dwwritten, NULL);
}
</code></pre>
<p>die funktioniert so, aber bei der operator funktion</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
cout&amp; operator&lt;&lt;(cout&amp; c, T str)
{
	c.write(str);
	return c;
}
</code></pre>
<p>kommen immer diese fehler:<br />
error LNK2001: Nicht aufgelöstes externes Symbol &quot;&quot;class cout &amp; __cdecl operator&lt;&lt;&lt;char const *&gt;(class cout &amp;,char const *)&quot; (???6PBD@@YAAAVcout@@AAV0@PBD@Z)".  
error LNK2001: Nicht aufgelöstes externes Symbol ""public: void __thiscall cout::write<int>(int)" (??write@H@cout@@QAEXH@Z)&quot;.</p>
<p>wo liegt der fehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/309823/nicht-aufgelöstes-externes-symbol-bei-template-funktion</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 01:58:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/309823.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Oct 2012 12:51:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Nicht aufgelöstes externes Symbol bei Template Funktion on Sun, 28 Oct 2012 12:51:59 GMT]]></title><description><![CDATA[<p>ich hab eine klasse erstellt um mit dem windows api konsolenausgaben durchzuführen, weil das mit cout nicht geht. die ausgabe und auch der überladene &lt;&lt; operator funktionieren, aber wenn ich beim operator templates benutzen will geht es nicht.<br />
zum schreiben in konsole hab ich diese funktion:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
void cout::write(T arg)
{
	ostringstream str; 
    str&lt;&lt;arg;
	  WriteConsole(hStdOut, str.str().c_str(),strlen(str.str().c_str()),&amp;dwwritten, NULL);
}
</code></pre>
<p>die funktioniert so, aber bei der operator funktion</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
cout&amp; operator&lt;&lt;(cout&amp; c, T str)
{
	c.write(str);
	return c;
}
</code></pre>
<p>kommen immer diese fehler:<br />
error LNK2001: Nicht aufgelöstes externes Symbol &quot;&quot;class cout &amp; __cdecl operator&lt;&lt;&lt;char const *&gt;(class cout &amp;,char const *)&quot; (???6PBD@@YAAAVcout@@AAV0@PBD@Z)".  
error LNK2001: Nicht aufgelöstes externes Symbol ""public: void __thiscall cout::write<int>(int)" (??write@H@cout@@QAEXH@Z)&quot;.</p>
<p>wo liegt der fehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2264916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2264916</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Sun, 28 Oct 2012 12:51:59 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht aufgelöstes externes Symbol bei Template Funktion on Sun, 28 Oct 2012 12:56:22 GMT]]></title><description><![CDATA[<p><a href="http://www.c-plusplus.net/forum/151578" rel="nofollow">http://www.c-plusplus.net/forum/151578</a></p>
<p>5.?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2264918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2264918</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 28 Oct 2012 12:56:22 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht aufgelöstes externes Symbol bei Template Funktion on Sun, 28 Oct 2012 12:56:46 GMT]]></title><description><![CDATA[<p>Was ist cout denn für ein Typ? (std::cout ist eine <em>Variable</em> vom Typ std::ostream).</p>
<p>In welchen Dateien hast du die beiden Funktionstemplates denn <em>defninert</em>? Im Header oder in der .cpp? Siehe dazu auch hier: <a href="http://www.c-plusplus.net/forum/246875" rel="nofollow">http://www.c-plusplus.net/forum/246875</a> (dritter Punkt) und hier: <a href="http://www.c-plusplus.net/forum/39467" rel="nofollow">http://www.c-plusplus.net/forum/39467</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2264919</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2264919</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Sun, 28 Oct 2012 12:56:46 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht aufgelöstes externes Symbol bei Template Funktion on Sun, 28 Oct 2012 14:12:04 GMT]]></title><description><![CDATA[<p>die funktionen direkt in der header datei zu definieren hat das problem wohl gelöst. ich dachte man könnte cout irgendwie ableiten und nur die methoden für die ausgabe ändern um die formatierungsoptionen und so noch beizubehalten, hab keine möglichkeit dafür gefunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2264941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2264941</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Sun, 28 Oct 2012 14:12:04 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht aufgelöstes externes Symbol bei Template Funktion on Sun, 28 Oct 2012 14:16:58 GMT]]></title><description><![CDATA[<p>cout ist keine Klasse. cout ist ein Objekt vom Typ ostream.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2264944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2264944</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 28 Oct 2012 14:16:58 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht aufgelöstes externes Symbol bei Template Funktion on Tue, 30 Oct 2012 09:36:59 GMT]]></title><description><![CDATA[<p>Du hast die eine Klasse gebaut, die &quot;cout&quot; heißt?<br />
Sicher, dass das eine gute Idee ist?<br />
Es gibt ja schon das Objekt namens cout vom Typ ostream.</p>
<p>Der Fehler sieht nach einer Missachtung der ODR aus (one definition rule).<br />
Punkt 5 der FAQ passt doch dazu, nicht?</p>
<p>Und so am Rande...</p>
<p>Nikolai schrieb:</p>
<blockquote>
<pre><code class="language-cpp">template &lt;typename T&gt;
void cout::write(T arg)
{
    ostringstream str; 
    str&lt;&lt;arg;
    WriteConsole(hStdOut, str.str().c_str(),strlen(str.str().c_str()),&amp;dwwritten, NULL);
}
</code></pre>
</blockquote>
<p>Warum so kompliziert? Du holst dir 2mal ein Stringobjekt ab und willst dann noch per strlen die Länge berechnen. Was hältst du von...</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
void cout::write(T const&amp; arg)
{
    using namespace std;
    ostringstream str; 
    str &lt;&lt; arg;
    string s = str.str();
    WriteConsole(hStdOut, s.c_str(), s.length(), &amp;dwwritten, NULL);
}
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2265510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2265510</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Tue, 30 Oct 2012 09:36:59 GMT</pubDate></item></channel></rss>