<?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[Klassentemplates: Instanziierung statischer Member]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>ich habe ein kleines Problem mit folgendem Code, welcher Teil eines Projektes von mir ist:</p>
<pre><code class="language-cpp">#ifndef TOKEN_HPP_
#define TOKEN_HPP_

#include &quot;Dictionary.hpp&quot;

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

        typedef Dictionary&lt;T&gt; DicType;

        static DicType dictionary;

        Token()
        {}

        virtual ~Token()
        {}

        virtual T operator() () = 0;
};

/*  ... */

//Der Typ Token&lt;T&gt;::DicType besitzt einen öffentlichen def. Konstruktor 
//ohne Argumente
template&lt;typename T&gt;
typename Token&lt;T&gt;::DicType Token&lt;T&gt;::dictionary;

//linker meldet &quot;undefined reference to Token&lt;double&gt;::dictionary&quot; !!
template&lt;&gt;
Token&lt;double&gt;::DicType Token&lt;double&gt;::dictionary;

#endif /*TOKEN_HPP_*/
</code></pre>
<p>Wenn man die beiden Zeilen, welche den Linker Fehler erzeugen, löscht, wird der Code anstandslos kompiliert (gcc 3.4.5 amd64). Ich benötige aber dringend ein Exemplar von Token&lt;T&gt;::DicType für den Typ double. Kann mir einer von euch sagen, was ich hierbei falsch mache?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/145789/klassentemplates-instanziierung-statischer-member</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 09:14:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/145789.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 May 2006 12:55:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Klassentemplates: Instanziierung statischer Member on Mon, 01 May 2006 15:56:56 GMT]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>ich habe ein kleines Problem mit folgendem Code, welcher Teil eines Projektes von mir ist:</p>
<pre><code class="language-cpp">#ifndef TOKEN_HPP_
#define TOKEN_HPP_

#include &quot;Dictionary.hpp&quot;

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

        typedef Dictionary&lt;T&gt; DicType;

        static DicType dictionary;

        Token()
        {}

        virtual ~Token()
        {}

        virtual T operator() () = 0;
};

/*  ... */

//Der Typ Token&lt;T&gt;::DicType besitzt einen öffentlichen def. Konstruktor 
//ohne Argumente
template&lt;typename T&gt;
typename Token&lt;T&gt;::DicType Token&lt;T&gt;::dictionary;

//linker meldet &quot;undefined reference to Token&lt;double&gt;::dictionary&quot; !!
template&lt;&gt;
Token&lt;double&gt;::DicType Token&lt;double&gt;::dictionary;

#endif /*TOKEN_HPP_*/
</code></pre>
<p>Wenn man die beiden Zeilen, welche den Linker Fehler erzeugen, löscht, wird der Code anstandslos kompiliert (gcc 3.4.5 amd64). Ich benötige aber dringend ein Exemplar von Token&lt;T&gt;::DicType für den Typ double. Kann mir einer von euch sagen, was ich hierbei falsch mache?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1048923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1048923</guid><dc:creator><![CDATA[schorf2k]]></dc:creator><pubDate>Mon, 01 May 2006 15:56:56 GMT</pubDate></item><item><title><![CDATA[Reply to Klassentemplates: Instanziierung statischer Member on Mon, 01 May 2006 13:10:46 GMT]]></title><description><![CDATA[<p>Ok, ich habe selbst herausfinden können, woran es lag.</p>
<pre><code class="language-cpp">template&lt;&gt;
Token&lt;double&gt;::DicType Token&lt;double&gt;::dictionary;
</code></pre>
<p>ist an sich noch keine Definition von Token&lt;double&gt;::dictionary,<br />
daher muss explizit eine Initialisierung erfolgen:</p>
<pre><code class="language-cpp">template&lt;&gt;
Token&lt;double&gt;::DicType Token&lt;double&gt;::dictionary = Token&lt;double&gt;::DicType();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1048932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1048932</guid><dc:creator><![CDATA[schorf2k]]></dc:creator><pubDate>Mon, 01 May 2006 13:10:46 GMT</pubDate></item></channel></rss>