<?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[Typedef in Template-Argument]]></title><description><![CDATA[<p>Hallo,</p>
<p>ist es irgendwie möglich in folgendem Szenario &quot;ty&quot; von &quot;T&quot; zu bekommen in base?</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
struct base
{
	typedef typename T::ty type; 
};

struct derived : base&lt;derived&gt;
{
	typedef int ty;    
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/271161/typedef-in-template-argument</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 13:42:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271161.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Jul 2010 17:09:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Typedef in Template-Argument on Fri, 23 Jul 2010 17:09:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ist es irgendwie möglich in folgendem Szenario &quot;ty&quot; von &quot;T&quot; zu bekommen in base?</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
struct base
{
	typedef typename T::ty type; 
};

struct derived : base&lt;derived&gt;
{
	typedef int ty;    
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1930823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930823</guid><dc:creator><![CDATA[FrEEzE2046]]></dc:creator><pubDate>Fri, 23 Jul 2010 17:09:42 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Fri, 23 Jul 2010 17:17:37 GMT]]></title><description><![CDATA[<p>Sorry, ich habe vergessen zu sagen, wo das Problem liegt.</p>
<pre><code>main.cpp|8|instantiated from here|
main.cpp|4|error: invalid use of incomplete type 'struct derived'|
main.cpp|7|error: forward declaration of 'struct derived'|
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1930825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930825</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 23 Jul 2010 17:17:37 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Fri, 23 Jul 2010 17:19:54 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Sorry, ich habe vergessen zu sagen, wo das Problem liegt.</p>
<pre><code>main.cpp|8|instantiated from here|
main.cpp|4|error: invalid use of incomplete type 'struct derived'|
main.cpp|7|error: forward declaration of 'struct derived'|
</code></pre>
</blockquote>
<p>Ja, schon klar. Also generell nicht möglich oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930827</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930827</guid><dc:creator><![CDATA[FrEEzE2046]]></dc:creator><pubDate>Fri, 23 Jul 2010 17:19:54 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Fri, 23 Jul 2010 17:21:09 GMT]]></title><description><![CDATA[<p>imho nicht ohne das ganze(derived) aufzusplitten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930828</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 23 Jul 2010 17:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Fri, 23 Jul 2010 17:27:45 GMT]]></title><description><![CDATA[<p>Okay, hab's hinbekommen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">template&lt;class T&gt;
struct ExtractType;

template&lt;template&lt;class&gt; class T, class U&gt;
struct ExtractType&lt;T&lt;U&gt;&gt;
{
	typedef U type;
};

struct other
{
	typedef double type;
};

template&lt;typename T&gt;
struct base
{
	typedef typename ExtractType&lt;T&gt;::type T0;
	typedef typename T0::type T1;
};

template&lt;typename U = other&gt;
struct derived : base&lt;derived&lt;U&gt;&gt;
{
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1930834</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930834</guid><dc:creator><![CDATA[FrEEzE2046]]></dc:creator><pubDate>Fri, 23 Jul 2010 17:27:45 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Fri, 23 Jul 2010 20:38:32 GMT]]></title><description><![CDATA[<p>Oder halt Traits nehmen, wenns losgelöster sein soll.</p>
<pre><code class="language-cpp">template &lt;class Key&gt;
struct TypeMap;

template &lt;&gt;
struct TypeMap&lt;MyClass&gt;
{
    typedef int Type;
};

template &lt;&gt;
struct TypeMap&lt;OtherClass&gt;
{
    typedef short Type;
};
</code></pre>
<p>Mit Makros kannst du das sogar kompakt und übersichtlich darstellen:</p>
<pre><code class="language-cpp">TYPE_MAP(MyClass, int)
TYPE_MAP(OtherClass, short)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1930903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930903</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 23 Jul 2010 20:38:32 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Sat, 24 Jul 2010 07:33:45 GMT]]></title><description><![CDATA[<p>FrEEzE2046 schrieb:</p>
<blockquote>
<p>Okay, hab's hinbekommen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">template&lt;class T&gt;
struct ExtractType;

template&lt;template&lt;class&gt; class T, class U&gt;
struct ExtractType&lt;T&lt;U&gt;&gt;
{
	typedef U type;
};

struct other
{
	typedef double type;
};

template&lt;typename T&gt;
struct base
{
	typedef typename ExtractType&lt;T&gt;::type T0;
	typedef typename T0::type T1;
};

template&lt;typename U = other&gt;
struct derived : base&lt;derived&lt;U&gt;&gt;
{
};
</code></pre>
</blockquote>
<p>Welchen Vorteil bringt dir das zusätzliche struct other?</p>
<pre><code class="language-cpp">template&lt;class T&gt;
struct ExtractType;

template&lt;template&lt;typename&gt; class T, typename U&gt;
struct ExtractType&lt;T&lt;U&gt; &gt;
{
    typedef U type;
};

template&lt;typename T&gt;
struct base
{
    typedef typename ExtractType&lt;T&gt;::type myType;
};

template&lt;typename T = double&gt;
struct derived : base&lt;derived&lt;T&gt; &gt;
{
    typedef T type;
};
</code></pre>
<p>Gruß,<br />
XSpille</p>
<p>EDIT: Dann noch ein zusätzlicher typedef und du hast exakt dein gewolltes Konstrukt (ohne internes struct als Work-Around)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930951</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 24 Jul 2010 07:33:45 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Sat, 24 Jul 2010 11:27:29 GMT]]></title><description><![CDATA[<p>type haengt vielleicht eben nicht von T ab...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931001</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sat, 24 Jul 2010 11:27:29 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Sat, 24 Jul 2010 17:55:36 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>type haengt vielleicht eben nicht von T ab...</p>
</blockquote>
<p>So ist es. Der Type in derived ist in allen Template-Varianten gleich ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931116</guid><dc:creator><![CDATA[FrEEzE2046]]></dc:creator><pubDate>Sat, 24 Jul 2010 17:55:36 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Sun, 25 Jul 2010 10:10:54 GMT]]></title><description><![CDATA[<p>FrEEzE2046 schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>type haengt vielleicht eben nicht von T ab...</p>
</blockquote>
<p>So ist es. Der Type in derived ist in allen Template-Varianten gleich ...</p>
</blockquote>
<p>Deswegen habe ich ja noch den typedef vorgeschlagen...</p>
<p>Alles klar...<br />
Bei deiner Variante ist er ja immer gleich:</p>
<pre><code class="language-cpp">struct otherB 
{ 
    typedef int type; 
};
</code></pre>
<pre><code class="language-cpp">derived&lt;otherB&gt; d;
</code></pre>
<p>Das zusätzliche struct 'erschwert' zwar eine Verwendung eines anderen Typen,<br />
aber das kann doch wohl nicht wirklich Ziel dieses structs sein...</p>
<p>EDIT: Wenn dir allerdings das typedef nicht gefällt, kannst du ja nochmal einen<br />
Typ von dem Template ableiten, dann kannste ihn garantiert nicht ändern.<br />
Ich persönlich finde es allerdings albern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931220</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 25 Jul 2010 10:10:54 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Wed, 28 Jul 2010 00:32:54 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin auf diesen Thread gestoßen und Frage mich,<br />
ob man so ein Konstrukt auch allgemein für typedefs<br />
mit unterschiedlichen Namen machen kann.<br />
Als Template-Parameter kann man ja afaik keinen String übergeben.<br />
Angenommen ich habe eine Klasse mit einem typedef für typeB,<br />
muss ich so eine Klasse dann wirklich noch einmal analog schreiben<br />
oder gibt es eine andere Möglichkkeit?</p>
<pre><code class="language-cpp">template&lt;class T&gt; 
struct ExtractType; 

template&lt;template&lt;typename&gt; class T, typename U&gt; 
struct ExtractType&lt;T&lt;U&gt; &gt; 
{ 
    typedef U type; 
};
</code></pre>
<p>Gruß,<br />
Definer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932872</guid><dc:creator><![CDATA[Definer]]></dc:creator><pubDate>Wed, 28 Jul 2010 00:32:54 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Wed, 28 Jul 2010 09:08:53 GMT]]></title><description><![CDATA[<p>Definer schrieb:</p>
<blockquote>
<p>ich bin auf diesen Thread gestoßen und Frage mich,<br />
ob man so ein Konstrukt auch allgemein für typedefs<br />
mit unterschiedlichen Namen machen kann.</p>
</blockquote>
<p>Welches Konstrukt meinst du jetzt genau? Kannst du es vielleicht mit ein wenig Code verdeutlichen? Bei deinem Post sehe ich nämlich den Zusammenhang zwischen Text und Code nicht wirklich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932957</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 28 Jul 2010 09:08:53 GMT</pubDate></item><item><title><![CDATA[Reply to Typedef in Template-Argument on Wed, 28 Jul 2010 12:37:03 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Definer schrieb:</p>
<blockquote>
<p>ich bin auf diesen Thread gestoßen und Frage mich,<br />
ob man so ein Konstrukt auch allgemein für typedefs<br />
mit unterschiedlichen Namen machen kann.</p>
</blockquote>
<p>Welches Konstrukt meinst du jetzt genau? Kannst du es vielleicht mit ein wenig Code verdeutlichen? Bei deinem Post sehe ich nämlich den Zusammenhang zwischen Text und Code nicht wirklich.</p>
</blockquote>
<p>Danke dir Nexus, aber ich glaub ich war wohl etwas verwirrt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1933091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1933091</guid><dc:creator><![CDATA[Definer]]></dc:creator><pubDate>Wed, 28 Jul 2010 12:37:03 GMT</pubDate></item></channel></rss>