<?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[Init const member mit non-type template argument]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich habe folgenden Code:</p>
<pre><code>enum known_types{ MSG_UNKNOWN, MSG_TEXT, MSG_FILE };	
    typedef unsigned char byte_t;

	struct handler {

		virtual ~handler() {}
		virtual byte_t type() const = 0;
		virtual void process(message&amp; msg, queue_t&amp; msg_queue) = 0;
	};

	template&lt;known_types type&gt;
	struct typed_handler : public handler {
		static const byte_t TYPE = type; // &lt;-- Fehler

		virtual ~typed_handler() {}
		byte_t type() const { return TYPE;  }
	};

	class text_handler : public typed_handler&lt;MSG_TEXT&gt; {
	public:
		text_handler(std::ostream&amp; ostream) : m_stream(ostream) {}
	}
</code></pre>
<p>Aber leider laesst micht mein VS2013 das nicht durchgehen mit folgender Begruendung:</p>
<blockquote>
<p>error C2057: expected constant expression</p>
</blockquote>
<p>Warum ist mein &quot;type&quot; keine const expression. Was ueberseh ich da grad?</p>
<p>Gruessle</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/323501/init-const-member-mit-non-type-template-argument</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 22:29:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/323501.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 02 Feb 2014 13:32:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Init const member mit non-type template argument on Sun, 02 Feb 2014 13:32:20 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich habe folgenden Code:</p>
<pre><code>enum known_types{ MSG_UNKNOWN, MSG_TEXT, MSG_FILE };	
    typedef unsigned char byte_t;

	struct handler {

		virtual ~handler() {}
		virtual byte_t type() const = 0;
		virtual void process(message&amp; msg, queue_t&amp; msg_queue) = 0;
	};

	template&lt;known_types type&gt;
	struct typed_handler : public handler {
		static const byte_t TYPE = type; // &lt;-- Fehler

		virtual ~typed_handler() {}
		byte_t type() const { return TYPE;  }
	};

	class text_handler : public typed_handler&lt;MSG_TEXT&gt; {
	public:
		text_handler(std::ostream&amp; ostream) : m_stream(ostream) {}
	}
</code></pre>
<p>Aber leider laesst micht mein VS2013 das nicht durchgehen mit folgender Begruendung:</p>
<blockquote>
<p>error C2057: expected constant expression</p>
</blockquote>
<p>Warum ist mein &quot;type&quot; keine const expression. Was ueberseh ich da grad?</p>
<p>Gruessle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381116</guid><dc:creator><![CDATA[stuxn]]></dc:creator><pubDate>Sun, 02 Feb 2014 13:32:20 GMT</pubDate></item><item><title><![CDATA[Reply to Init const member mit non-type template argument on Sun, 02 Feb 2014 13:38:37 GMT]]></title><description><![CDATA[<p>nimm mal die definition aus der klassendefinition raus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381118</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sun, 02 Feb 2014 13:38:37 GMT</pubDate></item><item><title><![CDATA[Reply to Init const member mit non-type template argument on Sun, 02 Feb 2014 13:42:39 GMT]]></title><description><![CDATA[<p>asfdlol schrieb:</p>
<blockquote>
<p>nimm mal die definition aus der klassendefinition raus.</p>
</blockquote>
<p>Hmm ja das Problem hat sich wohl erledigt. Man sollte nicht 2 Sachen den gleichen Bezeichner geben:</p>
<pre><code>template&lt;known_types type_arg&gt; // Bezeichner geaendert
    struct typed_handler : public handler {
        static const byte_t TYPE = type_arg;

        virtual ~typed_handler() {}
        byte_t type() const { return TYPE;  }
    };
</code></pre>
<p>Sorry tut mir echt leid. Leider hab ich das selber irgenwie uebersehen.</p>
<p>Gruessle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2381121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2381121</guid><dc:creator><![CDATA[stuxn]]></dc:creator><pubDate>Sun, 02 Feb 2014 13:42:39 GMT</pubDate></item></channel></rss>