<?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[template klasse]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;class T&gt;
class testbase {
protected:
	T	m_var;
public:
	testbase() {};
	~testbase() {};
};

class test: public testbase&lt;int&gt; {
public:
	test(): m_var(0) {}; // fehler, m_var is not a base or member
	~test() {};
	int get() {};
};
</code></pre>
<p>kann man m_var nicht in initialisierungsliste initialisieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/250253/template-klasse</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 05:54:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/250253.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Sep 2009 05:51:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template klasse on Wed, 16 Sep 2009 05:51:25 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;class T&gt;
class testbase {
protected:
	T	m_var;
public:
	testbase() {};
	~testbase() {};
};

class test: public testbase&lt;int&gt; {
public:
	test(): m_var(0) {}; // fehler, m_var is not a base or member
	~test() {};
	int get() {};
};
</code></pre>
<p>kann man m_var nicht in initialisierungsliste initialisieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779511</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Wed, 16 Sep 2009 05:51:25 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse on Wed, 16 Sep 2009 05:57:50 GMT]]></title><description><![CDATA[<p>T ist die Templateklasse, also:</p>
<pre><code class="language-cpp">template &lt;class T&gt; 
class testbase { 
protected: 
    T    m_var; 
public: 
    testbase() {}; 
    ~testbase() {}; 
}; 

template &lt;class T&gt;
class test: public testbase&lt;T&gt; { 
public: 
    test(): m_var(0) {}; 
    ~test() {}; 
    int get() {}; 
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1779518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779518</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 16 Sep 2009 05:57:50 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse on Wed, 16 Sep 2009 06:23:53 GMT]]></title><description><![CDATA[<p>m_var gehört zu testbase&lt;&gt;. Die Initialisierung von m_var via Initialisierungsliste kann nur im Konstruktor von testbase&lt;&gt; erfolgen. Du kannst aber einen entsprechenden Konstruktor dort anlegen und den von test aus aufrufen:</p>
<pre><code class="language-cpp">template &lt;class T&gt;
class testbase {
protected:
	T	m_var;

	// destruktor entweder protected machen...
	// ~testbase() {}
public:
	explicit testbase(T const&amp; x) : m_var(x) {}

	// ...oder public und virtual
	virtual ~testbase() {}
};

class test: public testbase&lt;int&gt; {
public:
	test(): testbase(0) {}
	// ~test() {} // brauchen wir nicht!
	int get() const {return this-&gt;m_var;}
};
</code></pre>
<p>Aber: public inheritance wird bei Dir scheinbar nicht gebraucht. Sonst hättest Du noch ein paar mehr (eventuell virtuelle) Funktionen in testbase&lt;&gt; drin. Wenn Du hier keine Polymorphie brauchst, lass das einfach mit der Vererbung. Du kannst ja auch ein testbase&lt;int&gt; als Element in test anlegen (oder privat von Erben, wenn's unbedingt sein muss).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779542</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779542</guid><dc:creator><![CDATA[sososo]]></dc:creator><pubDate>Wed, 16 Sep 2009 06:23:53 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse on Wed, 16 Sep 2009 06:25:06 GMT]]></title><description><![CDATA[<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>T ist die Templateklasse, also: [...]</p>
</blockquote>
<p>Was hat das bitte schön mit dem Problem zu tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779544</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779544</guid><dc:creator><![CDATA[sososo]]></dc:creator><pubDate>Wed, 16 Sep 2009 06:25:06 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse on Wed, 16 Sep 2009 07:02:41 GMT]]></title><description><![CDATA[<p>sososo schrieb:</p>
<blockquote>
<p>m_var gehört zu testbase&lt;&gt;. Die Initialisierung von m_var via Initialisierungsliste kann nur im Konstruktor von testbase&lt;&gt; erfolgen. Du kannst aber einen entsprechenden Konstruktor dort anlegen und den von test aus aufrufen:</p>
<pre><code class="language-cpp">template &lt;class T&gt;
class testbase {
protected:
	T	m_var;

	// destruktor entweder protected machen...
	// ~testbase() {}
public:
	explicit testbase(T const&amp; x) : m_var(x) {}

	// ...oder public und virtual
	virtual ~testbase() {}
};

class test: public testbase&lt;int&gt; {
public:
	test(): testbase(0) {}
	// ~test() {} // brauchen wir nicht!
	int get() const {return this-&gt;m_var;}
};
</code></pre>
<p>Aber: public inheritance wird bei Dir scheinbar nicht gebraucht. Sonst hättest Du noch ein paar mehr (eventuell virtuelle) Funktionen in testbase&lt;&gt; drin. Wenn Du hier keine Polymorphie brauchst, lass das einfach mit der Vererbung. Du kannst ja auch ein testbase&lt;int&gt; als Element in test anlegen (oder privat von Erben, wenn's unbedingt sein muss).</p>
</blockquote>
<p>n1 loesung, vielen dank, dein code sieht sehr ordentlich aus, profi coder wat</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779566</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779566</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Wed, 16 Sep 2009 07:02:41 GMT</pubDate></item></channel></rss>