<?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[Überschreiben von typedef in abgeleitetem Template]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich habe ein Funktion, in der für die aktuelle Klasse ein Objekt erstellt<br />
werden soll. Konkret dachte ich an ein Model, auf dem man ein create_view();<br />
aufrufen kann. Da es ein Template ist, hatte ich eigentlich gehofft,<br />
dass für die abgeleitete Klasse die Funktion auf Basis des typedef darin<br />
neu erstellt wird, leider wird sie es nicht:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class A{};

template&lt;typename T&gt;
class FooBar{
public:
        FooBar(){
                std::cout &lt;&lt; &quot;normal&quot; &lt;&lt; std::endl;
        }
};

template&lt;typename T&gt;
class Bar;

template&lt;typename T&gt;
class FooBar&lt;Bar&lt;T&gt; &gt;{
public:
        FooBar(){
                std::cout &lt;&lt; &quot;specialized&quot; &lt;&lt; std::endl;
        }
};

template&lt;typename T&gt;
class Foo{
public:
        typedef Foo&lt;T&gt; my_type;

        FooBar&lt;my_type&gt;* foo(){
                return new FooBar&lt;my_type&gt;();
        }

        void foo2(){
                FooBar&lt;my_type&gt;();
        }
};

template&lt;typename T&gt;
class Bar : public Foo&lt;T&gt;{
public:
        typedef Bar&lt;T&gt; my_type;

/*      FooBar&lt;my_type&gt;* foo(){
                return new FooBar&lt;my_type&gt;();
        }

        void foo2(){
                FooBar&lt;my_type&gt;();
        }*/

};

int main(int argc, char** arg) {
        Foo&lt;A&gt; foo;
        foo.foo();
        foo.foo2();
        Bar&lt;A&gt; bar;
        bar.foo();
        bar.foo2();
        return 0;
}
</code></pre>
<blockquote>
<p>normal<br />
normal<br />
normal<br />
normal</p>
</blockquote>
<p>Bei der Funktion mit Rückgabe-Typ, kann ich es nachvollziehen, weswegen<br />
er es nicht macht (Unterschiedliche Funktionssignaturen)</p>
<p>Ich möchte also quasi das Verhalten als würde ich die Funktionen wie angedeutet<br />
kopieren:</p>
<blockquote>
<p>normal<br />
normal<br />
specialized<br />
specialized</p>
</blockquote>
<p>Gibt es eine Möglichkeit mein abgestrebtes Verhalten zu verwirklichen<br />
oder muss ich in allen abgeleiteten Klassen die Funktion überschreiben?</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/284383/überschreiben-von-typedef-in-abgeleitetem-template</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 02:27:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/284383.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 Mar 2011 10:55:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überschreiben von typedef in abgeleitetem Template on Thu, 31 Mar 2011 11:37:47 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich habe ein Funktion, in der für die aktuelle Klasse ein Objekt erstellt<br />
werden soll. Konkret dachte ich an ein Model, auf dem man ein create_view();<br />
aufrufen kann. Da es ein Template ist, hatte ich eigentlich gehofft,<br />
dass für die abgeleitete Klasse die Funktion auf Basis des typedef darin<br />
neu erstellt wird, leider wird sie es nicht:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class A{};

template&lt;typename T&gt;
class FooBar{
public:
        FooBar(){
                std::cout &lt;&lt; &quot;normal&quot; &lt;&lt; std::endl;
        }
};

template&lt;typename T&gt;
class Bar;

template&lt;typename T&gt;
class FooBar&lt;Bar&lt;T&gt; &gt;{
public:
        FooBar(){
                std::cout &lt;&lt; &quot;specialized&quot; &lt;&lt; std::endl;
        }
};

template&lt;typename T&gt;
class Foo{
public:
        typedef Foo&lt;T&gt; my_type;

        FooBar&lt;my_type&gt;* foo(){
                return new FooBar&lt;my_type&gt;();
        }

        void foo2(){
                FooBar&lt;my_type&gt;();
        }
};

template&lt;typename T&gt;
class Bar : public Foo&lt;T&gt;{
public:
        typedef Bar&lt;T&gt; my_type;

/*      FooBar&lt;my_type&gt;* foo(){
                return new FooBar&lt;my_type&gt;();
        }

        void foo2(){
                FooBar&lt;my_type&gt;();
        }*/

};

int main(int argc, char** arg) {
        Foo&lt;A&gt; foo;
        foo.foo();
        foo.foo2();
        Bar&lt;A&gt; bar;
        bar.foo();
        bar.foo2();
        return 0;
}
</code></pre>
<blockquote>
<p>normal<br />
normal<br />
normal<br />
normal</p>
</blockquote>
<p>Bei der Funktion mit Rückgabe-Typ, kann ich es nachvollziehen, weswegen<br />
er es nicht macht (Unterschiedliche Funktionssignaturen)</p>
<p>Ich möchte also quasi das Verhalten als würde ich die Funktionen wie angedeutet<br />
kopieren:</p>
<blockquote>
<p>normal<br />
normal<br />
specialized<br />
specialized</p>
</blockquote>
<p>Gibt es eine Möglichkeit mein abgestrebtes Verhalten zu verwirklichen<br />
oder muss ich in allen abgeleiteten Klassen die Funktion überschreiben?</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2042718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2042718</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Thu, 31 Mar 2011 11:37:47 GMT</pubDate></item><item><title><![CDATA[Reply to Überschreiben von typedef in abgeleitetem Template on Thu, 31 Mar 2011 13:52:20 GMT]]></title><description><![CDATA[<p>Zur Zeit tendiere ich zu einer Lösung ala:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
class Helper{
public:
        typedef T my_type;

        FooBar&lt;my_type&gt;* foo(){
                return new FooBar&lt;my_type&gt;();
        }

        void foo2(){
                FooBar&lt;my_type&gt;();
        }
};

template&lt;typename T&gt;
class Foo : public Helper&lt;Foo &lt;T&gt; &gt;{
public:
        typedef Helper&lt;Foo&lt;T&gt; &gt; type;
        // ...
};

template&lt;typename T&gt;
class Bar : public Foo&lt;T&gt;, public Helper&lt;Bar&lt;T&gt; &gt;{
public:
        typedef Helper&lt;Bar&lt;T&gt; &gt; type;
};

int main(int argc, char** arg) {
        Foo&lt;A&gt; foo;
        foo.foo();
        foo.foo2();
        Bar&lt;A&gt; bar;
        bar.Bar::type::foo();
        bar.Bar::type::foo2();
        return 0;
}
</code></pre>
<p>EDIT: Eigentlich gefällt mir das gar nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2042783</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2042783</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Thu, 31 Mar 2011 13:52:20 GMT</pubDate></item></channel></rss>