<?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[Argumente einer Vorlagen-Klasse]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>wenn ich eine Vorlagen-Klasse habe, die relativ umfangreich ist, und eine Memberfunktion einen zusätzlichen Parameter benötigt, muss ich dann der ganzen Vorlagen-Klasse zwei geben?</p>
<p>Z.B.</p>
<pre><code class="language-cpp">template&lt;class T, class DTO&gt;
class class_name
{
    T m_data;
    // ...

public:
    class_name(T data);
    // ...
    void function(DTO dto);
};
</code></pre>
<p>Es gibt in der ganzen Klasse nur eine Funktion die den Parameter DTO benötig. Wenn ich aber folgendes schreibe</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class class_name
{
    T m_data;
    // ...

public:
    class_name(T data);
    // ...
    template&lt;class DTO&gt;void function(DTO dto);
};
</code></pre>
<p>Setzt der Compiler T für DTO ein und ich bekomme eine Fehlermeldung.</p>
<p>Wie löst man so etwas, bzw. was mache ich falsch?<br />
Bin um jede Hilfe dankbar.</p>
<p>Viele Grüße<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/154430/argumente-einer-vorlagen-klasse</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 23:35:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/154430.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Jul 2006 08:27:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 08:27:47 GMT]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>wenn ich eine Vorlagen-Klasse habe, die relativ umfangreich ist, und eine Memberfunktion einen zusätzlichen Parameter benötigt, muss ich dann der ganzen Vorlagen-Klasse zwei geben?</p>
<p>Z.B.</p>
<pre><code class="language-cpp">template&lt;class T, class DTO&gt;
class class_name
{
    T m_data;
    // ...

public:
    class_name(T data);
    // ...
    void function(DTO dto);
};
</code></pre>
<p>Es gibt in der ganzen Klasse nur eine Funktion die den Parameter DTO benötig. Wenn ich aber folgendes schreibe</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class class_name
{
    T m_data;
    // ...

public:
    class_name(T data);
    // ...
    template&lt;class DTO&gt;void function(DTO dto);
};
</code></pre>
<p>Setzt der Compiler T für DTO ein und ich bekomme eine Fehlermeldung.</p>
<p>Wie löst man so etwas, bzw. was mache ich falsch?<br />
Bin um jede Hilfe dankbar.</p>
<p>Viele Grüße<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105104</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Thu, 27 Jul 2006 08:27:47 GMT</pubDate></item><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 08:40:15 GMT]]></title><description><![CDATA[<p>Der Codeabschnitt ist korrekt.</p>
<p>Ich könnte den Post hier eigentlich beenden ;), dennoch:<br />
- Wie lautet die Fehlermeldung?<br />
- Wie ist die Implementierung von void function&lt;&gt;?</p>
<p>EDIT:<br />
- Wie versuchst Du void function&lt;&gt; aufzurufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105112</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 27 Jul 2006 08:40:15 GMT</pubDate></item><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 08:44:57 GMT]]></title><description><![CDATA[<p>evtl. benutzt du auch einen schlechten compiler, der member templates nicht ausserhalb der klasse definieren kann bsp: VC6.<br />
zumindest sieht es so aus das deine definitionen ausserhalb wären.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105117</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Thu, 27 Jul 2006 08:44:57 GMT</pubDate></item><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 09:02:47 GMT]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>der gegebene Code war nur ein vereinfachtes Beispiel. Im Original sieht es so aus.</p>
<pre><code class="language-cpp">namespace Tree
{
	typedef unsigned int qtLocCode;

	template&lt;class T&gt;
	class qtCell
	{
	public:
		// constructors
		qtCell(T *Data, qtLocCode xCode = 0, qtLocCode yCode = 0, 
			   qtLocCode Level = QT_ROOT_LEVEL, qtCell&lt;T&gt; *Parent = 0);
		~qtCell(void);

		// ...

		template&lt;class DTO&gt;
		void qtBranch(DTO *dto);   // branch this Node
		void qtUnbranch(void);	// remove all sons from here

		class qtBranchError {};	// class for exception handling
		class qtTreeSizeError {};

	private:
		int			key;		// HACK this initializer can be removed if the comparison of addresses in the neighbour searching dialog works.
		qtLocCode	xLocCode;	// X locational code
		qtLocCode	yLocCode;	// Y locational code
		qtLocCode	level;		// Cell level in hierarchy (smallest cell has level 0)
		qtCell		*parent;	// Pointer to parent cell
		qtCell		**children;	// Pointer to first of 4 contiguous child cells
		T			*data;		// Application specific cell data

		//-------------------------------------------------------------------------------
		// Maximum quadtree depth and related constants
		//-------------------------------------------------------------------------------
		static qtLocCode QT_N_LEVELS;		// Number of possible levels in the quadtree (def. = 16)
		static qtLocCode QT_ROOT_LEVEL;		// Level of root cell (def. = QT_N_LEVELS - 1)
		// For converting positions to locational codes (QT_MAX_VAL = 2^QT_ROOT_LEVEL)
		static double QT_MAX_VAL;			// 32768.0 

		static unsigned int counter;		
	};

    // Declaration of helper functions
    // ...
}

template&lt;class T, class DTO&gt;
void Tree::qtCell&lt;T&gt;::qtBranch(DTO *dto)
/*
	The qtBranch() function checks first if the cell is already branched and 
	if so it throws an exception. Second it checks if the level of the current
	cell is zero. This mean that the tree has reached its max height and 
	qtBranch() throws an exception.
	Then it calls the function T.Branch() to get the data for the new cells. 
	Further it determis the childs location codes and creates them.
*/
{
	if (children) throw qtBranchError();
	if (!level) throw qtTreeSizeError();

	T **Data = data-&gt;Branch(dto);
	qtLocCode Level = level - 1;
	qtLocCode branch = 1 &lt;&lt; Level;

	children = new qtCell *[4];
	children[0] = new qtCell(Data[0], xLocCode, yLocCode, Level, this);
	children[1] = new qtCell(Data[1], xLocCode | branch, yLocCode, Level, this);
	children[2] = new qtCell(Data[2], xLocCode, yLocCode | branch, Level, this);
	children[3] = new qtCell(Data[3], xLocCode | branch, yLocCode | branch, Level, this);

	// delete only the pointer to the data not the data themselfe.
	delete[] Data;
	Data = 0;
}
</code></pre>
<p>und die zugehörige Fehlermeldung ist die folgende.</p>
<pre><code>c:\MitsubishiQuadTree.h(364) : error C2244: 'qtBranch': Keine Übereinstimmung für Funktionsdefinition mit vorhandener Deklaration gefunden
        Definition
        'void Tree::qtCell&lt;T&gt;::qtBranch(T2 *)'
        Vorhandene Deklarationen
        'void Tree::qtCell&lt;T&gt;::qtBranch(DTO *)'
</code></pre>
<p>Als Compiler verwende ich MS <a href="http://VS2003.net" rel="nofollow">VS2003.net</a> und die Definitionen stehen im gleichen File wie die Deklaration.</p>
<p>Herzlichen Dank für die Hilfe<br />
Viele Grüße</p>
<p>EDIT: Ich rufe die funktion folgendermaßen auf</p>
<pre><code class="language-cpp">(*temp)-&gt;qtBranch(ppd);
</code></pre>
<p>wobei temp ein iterator auf ein qtCell&lt;T&gt; object ist, da ich die leaves in einer Liste verwalte...<br />
ppd ist eine Struktur die die nötigen parameter zusammen fasst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105128</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Thu, 27 Jul 2006 09:02:47 GMT</pubDate></item><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 08:59:01 GMT]]></title><description><![CDATA[<p>auf den ersten blick würde ich sagen so</p>
<pre><code class="language-cpp">template&lt;
    class T&gt;
template&lt;
    class DTO&gt;
void Tree::qtCell&lt;T&gt;::qtBranch(DTO *dto)
{
// ...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1105137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105137</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Thu, 27 Jul 2006 08:59:01 GMT</pubDate></item><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 09:02:10 GMT]]></title><description><![CDATA[<p>Es gibt ja auch keine Funktion qtBranch in der Klasse qtCell&lt;T, DTO&gt; sondern nur eine Funktion qtBranch&lt;DTO&gt; in der Klasse qtCell&lt;T&gt; ;). Die korrekte Definition müsste wie folgt lauten:</p>
<pre><code class="language-cpp">template&lt;class T&gt; // &quot;äusseres&quot; Template
template&lt;class DTO&gt; // &quot;inneres&quot; Template
Tree::qtCell&lt;T&gt;::qtBranch(DTO* dto)
{
//...
}
</code></pre>
<p>Damit weiss der Compiler, dass es sich um das Template qtBranch&lt;DTO&gt;(DTO*) innerhalb des Templates qtCell&lt;T&gt; handelt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105141</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 27 Jul 2006 09:02:10 GMT</pubDate></item><item><title><![CDATA[Reply to Argumente einer Vorlagen-Klasse on Thu, 27 Jul 2006 09:08:35 GMT]]></title><description><![CDATA[<p>Hallo miteinander,<br />
genau das war's.</p>
<p>Herzlichen Dank für die schnelle Hilfe.</p>
<p>Viele Grüße<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105143</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Thu, 27 Jul 2006 09:08:35 GMT</pubDate></item></channel></rss>