<?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[Hat eine Klasse ein typedef definiert?]]></title><description><![CDATA[<p>Ist es möglich zu überprüfen ob eine Klasse ein typedef definiert hat,<br />
aber ohne dabei ein mögliches typedef mit dem exakt gleichen Name in einer Basisklasse zu be­rück­sich­ti­gen.</p>
<p>also</p>
<pre><code>struct Base
{
typedef int MyType;
}

struct Derived : Base
{

}
</code></pre>
<p>Nun soll zur Compile zeit überprüft werden ob <strong>Derived</strong> das typedef <strong>MyType</strong> definiert hat. Hat es aber nicht.<br />
Ist das Problem mit standard C++ zu lösen, ja oder nein?<br />
Wenn ja, wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/318217/hat-eine-klasse-ein-typedef-definiert</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 11:52:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318217.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 04 Jul 2013 20:45:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hat eine Klasse ein typedef definiert? on Thu, 04 Jul 2013 20:45:32 GMT]]></title><description><![CDATA[<p>Ist es möglich zu überprüfen ob eine Klasse ein typedef definiert hat,<br />
aber ohne dabei ein mögliches typedef mit dem exakt gleichen Name in einer Basisklasse zu be­rück­sich­ti­gen.</p>
<p>also</p>
<pre><code>struct Base
{
typedef int MyType;
}

struct Derived : Base
{

}
</code></pre>
<p>Nun soll zur Compile zeit überprüft werden ob <strong>Derived</strong> das typedef <strong>MyType</strong> definiert hat. Hat es aber nicht.<br />
Ist das Problem mit standard C++ zu lösen, ja oder nein?<br />
Wenn ja, wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336638</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336638</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Thu, 04 Jul 2013 20:45:32 GMT</pubDate></item><item><title><![CDATA[Reply to Hat eine Klasse ein typedef definiert? on Thu, 04 Jul 2013 22:04:23 GMT]]></title><description><![CDATA[<p>Im Allgemeinen eher Nein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336649</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Thu, 04 Jul 2013 22:04:23 GMT</pubDate></item><item><title><![CDATA[Reply to Hat eine Klasse ein typedef definiert? on Thu, 04 Jul 2013 22:35:04 GMT]]></title><description><![CDATA[<p>Mir ist keine standardisierte Möglichkeit dazu bekannt, wenn sollte eine vom Compiler angeboten werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336656</guid><dc:creator><![CDATA[Youka]]></dc:creator><pubDate>Thu, 04 Jul 2013 22:35:04 GMT</pubDate></item><item><title><![CDATA[Reply to Hat eine Klasse ein typedef definiert? on Thu, 04 Jul 2013 22:52:45 GMT]]></title><description><![CDATA[<p>Wozu braucht man so etwas?</p>
<pre><code class="language-cpp">struct foo : Derived, Base {};
</code></pre>
<p>und dann schauen, ob ein (eindeutiges) foo::MyType existiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336657</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336657</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 04 Jul 2013 22:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Hat eine Klasse ein typedef definiert? on Fri, 05 Jul 2013 05:35:29 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Wozu braucht man so etwas?</p>
<pre><code class="language-cpp">struct foo : Derived, Base {};
</code></pre>
<p>und dann schauen, ob ein (eindeutiges) foo::MyType existiert.</p>
</blockquote>
<p>Ich verstehe nicht was du meinst. In dem Fall hat foo auch wieder ein MyType.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336666</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Fri, 05 Jul 2013 05:35:29 GMT</pubDate></item><item><title><![CDATA[Reply to Hat eine Klasse ein typedef definiert? on Fri, 05 Jul 2013 08:43:45 GMT]]></title><description><![CDATA[<p>Nash26 schrieb:</p>
<blockquote>
<p>camper schrieb:</p>
<blockquote>
<p>Wozu braucht man so etwas?</p>
<pre><code class="language-cpp">struct foo : Derived, Base {};
</code></pre>
<p>und dann schauen, ob ein (eindeutiges) foo::MyType existiert.</p>
</blockquote>
<p>Ich verstehe nicht was du meinst. In dem Fall hat foo auch wieder ein MyType.</p>
</blockquote>
<p>Keineswegs, schließlich wäre die Auflösung mehrdeutig.</p>
<pre><code class="language-cpp">#include &lt;type_traits&gt;
#include &lt;utility&gt;

struct Base { typedef int MyType; };
struct Derived : Base { };
struct Derived2 : Base { using Base::MyType; };
struct Derived3 : Base { typedef char MyType; };
struct Derived4 : Base { typedef int MyType; };

struct foo : Derived, Base {};
struct bar : Derived2, Base {};
struct baz : Derived3, Base {};
struct boo : Derived4, Base {};

template &lt;typename T&gt; struct identity { typedef T type; };

template &lt;typename T, typename = typename T::MyType&gt;
std::true_type has_MyType(identity&lt;T&gt;);
std::false_type has_MyType(...);

int main()
{
    static_assert( decltype(has_MyType(identity&lt;Base&gt;()))::value, &quot;Base should have MyType&quot; );
    static_assert( decltype(has_MyType(identity&lt;Derived&gt;()))::value, &quot;Derived should have MyType&quot; );
    static_assert( decltype(has_MyType(identity&lt;Derived2&gt;()))::value, &quot;Derived2 should have MyType&quot; );
    static_assert( decltype(has_MyType(identity&lt;Derived3&gt;()))::value, &quot;Derived3 should have MyType&quot; );

    static_assert( decltype(has_MyType(identity&lt;foo&gt;()))::value, &quot;should have inherited MyType&quot; );
    static_assert( decltype(has_MyType(identity&lt;bar&gt;()))::value, &quot;should have inherited MyType&quot; );
    static_assert( !decltype(has_MyType(identity&lt;baz&gt;()))::value, &quot;should be ambigous&quot; );
    static_assert( !decltype(has_MyType(identity&lt;boo&gt;()))::value, &quot;should be ambigous&quot; );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2336696</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336696</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 05 Jul 2013 08:43:45 GMT</pubDate></item></channel></rss>