<?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[templates mit mehreren Rückgabe Typen]]></title><description><![CDATA[<p>Ich möchte aus folgender Funktion entweder ein QString, bool oder int erhalten.<br />
Da templates type safe sind habe ich das Problem, das z.b. bei folgendem Aufruf der Compiler ein nicht typ sicheres template generiert.</p>
<p>int testi = Settings::get&lt;int&gt;(&quot;settingA&quot;);</p>
<p>Der Compiler versucht natürlich str_data in ein int zu casten, was nicht gelingt. Jedoch wird er bei typename int diese Code Stelle nie erreichen. Dennoch muss sie type safe sein. Wie kann ich das mittels templates auf die Reihe kriegen um nicht für jeden Typ eine eigene get Methode bauen zu müssen?</p>
<p>Wenn ich typename QString verwende habe ich grundsätzlich das gleiche Problem, jedoch kann der Compiler hier ein int in einen QString casten.</p>
<p>setting-&gt;data ist ein int und setting-&gt;str_data ist ein QString</p>
<pre><code class="language-cpp">template&lt;typename T&gt; static T get(QString name) {
        Settings* setting = findSetting(name);
        if (typeid(T) == typeid(QString)) {
            return (T)setting-&gt;str_data;
        } else if (typeid(T) == typeid(int)) {
            return (T)setting-&gt;data;
        } else if (typeid(T) == typeid(bool)) {
            return (T)(setting-&gt;data == 0 ? false : true);
        }
        throw Exception(&quot;unsupported type of setting&quot;);
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/297035/templates-mit-mehreren-rückgabe-typen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 14:32:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297035.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Dec 2011 16:13:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 16:17:26 GMT]]></title><description><![CDATA[<p>Ich möchte aus folgender Funktion entweder ein QString, bool oder int erhalten.<br />
Da templates type safe sind habe ich das Problem, das z.b. bei folgendem Aufruf der Compiler ein nicht typ sicheres template generiert.</p>
<p>int testi = Settings::get&lt;int&gt;(&quot;settingA&quot;);</p>
<p>Der Compiler versucht natürlich str_data in ein int zu casten, was nicht gelingt. Jedoch wird er bei typename int diese Code Stelle nie erreichen. Dennoch muss sie type safe sein. Wie kann ich das mittels templates auf die Reihe kriegen um nicht für jeden Typ eine eigene get Methode bauen zu müssen?</p>
<p>Wenn ich typename QString verwende habe ich grundsätzlich das gleiche Problem, jedoch kann der Compiler hier ein int in einen QString casten.</p>
<p>setting-&gt;data ist ein int und setting-&gt;str_data ist ein QString</p>
<pre><code class="language-cpp">template&lt;typename T&gt; static T get(QString name) {
        Settings* setting = findSetting(name);
        if (typeid(T) == typeid(QString)) {
            return (T)setting-&gt;str_data;
        } else if (typeid(T) == typeid(int)) {
            return (T)setting-&gt;data;
        } else if (typeid(T) == typeid(bool)) {
            return (T)(setting-&gt;data == 0 ? false : true);
        }
        throw Exception(&quot;unsupported type of setting&quot;);
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2158079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158079</guid><dc:creator><![CDATA[PiCiJi]]></dc:creator><pubDate>Sat, 17 Dec 2011 16:17:26 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 16:45:12 GMT]]></title><description><![CDATA[<p>Hi PiCiJi,</p>
<p>ich hoffe folgendes hilft dir weiter:</p>
<pre><code class="language-cpp">#include &lt;string&gt;

template&lt;typename T&gt; class type_info{};

static int get(type_info&lt;int&gt; t, const std::string&amp; s){
	return 0;
}

static std::string get(type_info&lt;std::string&gt; t, const std::string&amp; s){
	return &quot;string&quot;;
}

template&lt;typename T&gt;
static T get(type_info&lt;T&gt; t, const std::string&amp; s){
	throw std::string(&quot;Oops&quot;);
}

template&lt;typename T&gt; static T get(const std::string&amp; name) {
	return get(type_info&lt;T&gt;(), name);
}

int main(){
	int i = get&lt;int&gt;(std::string(&quot;Hallo&quot;));
	std::string s = get&lt;std::string&gt;(std::string(&quot;Hallo&quot;));
	double d = get&lt;double&gt;(std::string(&quot;Hallo&quot;));
}
</code></pre>
<p>Ich denke, es ist genau das, was du suchst.</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158085</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 17 Dec 2011 16:45:12 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 16:46:57 GMT]]></title><description><![CDATA[<p>Warum willst du nicht für jeden Typ eine eigene get()-Funktion schreiben? Momentan schreibst du doch auch für jeden Typ einen eigenen if()-Block.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158086</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Sat, 17 Dec 2011 16:46:57 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 16:50:34 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24036">@XSpille</a>: Was genau ist an deiner Lösung besser als an Spezialisierung? Machst du das, weil Spezialisierung angeblich &quot;böse&quot; ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158088</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Sat, 17 Dec 2011 16:50:34 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 16:57:45 GMT]]></title><description><![CDATA[<p>Ist das nicht sowieso ein Fall für einen <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/variant.html" rel="nofollow">Variant-Container</a>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158089</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 17 Dec 2011 16:57:45 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 16:59:27 GMT]]></title><description><![CDATA[<p>Nein, das ist ein klassischer Fall für verschiedene Funktionen. Das Template bringt hier nur Nachteile.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158091</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 17 Dec 2011 16:59:27 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 17:28:29 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24036">@XSpille</a> danke das funktioniert</p>
<pre><code class="language-cpp">template&lt;typename T&gt; class type_info{};

    static int get(type_info&lt;int&gt; t, const QString&amp; name){
        Settings* setting = findSetting(name);
        return setting-&gt;data;
    }

    static void set(type_info&lt;int&gt; t, const QString&amp; name, int value){
        Settings* setting = findSetting(name);
        setting-&gt;data = value;
    }

    static int get(type_info&lt;bool&gt; t, const QString&amp; name){
        Settings* setting = findSetting(name);
        return setting-&gt;data == 0 ? false : true;
    }

    static void set(type_info&lt;bool&gt; t, const QString&amp; name, bool value){
        Settings* setting = findSetting(name);
        setting-&gt;data = !value ? 0 : 1;
    }

    static QString get(type_info&lt;QString&gt; t, const QString&amp; name){
        Settings* setting = findSetting(name);
        return setting-&gt;str_data;
    }

    static void set(type_info&lt;QString&gt; t, const QString&amp; name, QString value){
        Settings* setting = findSetting(name);
        setting-&gt;str_data = value;
    }

    template&lt;typename T&gt;
    static T get(type_info&lt;T&gt; t, const QString&amp; name){
        throw Exception(&quot;unsupported type of setting&quot;);
    }

    template&lt;typename T&gt;
    static void set(type_info&lt;T&gt; t, const QString&amp; name, T value){
        throw Exception(&quot;unsupported type of setting&quot;);
    }

    template&lt;typename T&gt; static T get(const QString&amp; name) {
        return get(type_info&lt;T&gt;(), name);
    }

    template&lt;typename T&gt; static void set(const QString&amp; name, T value) {
        set(type_info&lt;T&gt;(), name, value);
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2158104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158104</guid><dc:creator><![CDATA[PiCiJi]]></dc:creator><pubDate>Sat, 17 Dec 2011 17:28:29 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 17:57:01 GMT]]></title><description><![CDATA[<p>wxSkip schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24036">@XSpille</a>: Was genau ist an deiner Lösung besser als an Spezialisierung? Machst du das, weil Spezialisierung angeblich &quot;böse&quot; ist?</p>
</blockquote>
<p>Liegt wahrscheinlich daran, dass ich template-Funktionen eigentlich nie spezialisiere. Ich poste dann PiCiJi mal, was du meintest:</p>
<pre><code class="language-cpp">#include &lt;string&gt; 

template&lt;typename T&gt; class type_info{}; 

template&lt;typename T&gt; 
static T get(type_info&lt;T&gt; t, const std::string&amp; s){ 
    throw std::string(&quot;Oops&quot;); 
} 

template&lt;&gt;
int get&lt;&gt;(type_info&lt;int&gt; t, const std::string&amp; s){ 
    return 0; 
} 

template&lt;&gt;
std::string get&lt;&gt;(type_info&lt;std::string&gt; t, const std::string&amp; s){ 
    return &quot;string&quot;; 
} 

template&lt;typename T&gt; static T get(const std::string&amp; name) { 
    return get(type_info&lt;T&gt;(), name); 
} 

int main(){ 
    int i = get&lt;int&gt;(std::string(&quot;Hallo&quot;)); 
    std::string s = get&lt;std::string&gt;(std::string(&quot;Hallo&quot;)); 
    double d = get&lt;double&gt;(std::string(&quot;Hallo&quot;)); 
}
</code></pre>
<p>camper schrieb:</p>
<blockquote>
<p>Ist das nicht sowieso ein Fall für einen <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/variant.html" rel="nofollow">Variant-Container</a>?</p>
</blockquote>
<p>Sehe ich absolut nicht so...</p>
<p>cooky451 schrieb:</p>
<blockquote>
<p>Nein, das ist ein klassischer Fall für verschiedene Funktionen. Das Template bringt hier nur Nachteile.</p>
</blockquote>
<p>Wahrscheinlich hast du recht, aber in Template-Funktionen macht sowas schon manchmal Sinn...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158123</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158123</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 17 Dec 2011 17:57:01 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 17:57:14 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Nein, das ist ein klassischer Fall für verschiedene Funktionen. Das Template bringt hier nur Nachteile.</p>
</blockquote>
<p>Außer, er will es aus einem anderen Template heraus benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158124</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Sat, 17 Dec 2011 17:57:14 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 18:49:11 GMT]]></title><description><![CDATA[<p>Ich versteh nicht ganz was ein <code>throw</code> in dieser Funktion zu suchen hat, das ist ja kein runtime error. Ich würde hier einfach die Funktion spezialisieren (wie schon von anderen angemerkt):</p>
<pre><code class="language-cpp">template&lt; class T &gt;
T get( const std::string &amp; )
{
    static_assert( sizeof( T ) == 0 , &quot;get&lt; T &gt; - unsupported Type&quot; );
}
template&lt;&gt;
int get&lt; int &gt;( const std::string &amp; )
{
    //...
}
template&lt;&gt;
bool get&lt; bool &gt;( const std::string &amp; )
{
    //...
}
</code></pre>
<p>Warum Funktionstemplates nicht spezialisieren sollte hängt mit der overload resolution zu tun, und die spielt hier ja keine Rolle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158139</guid><dc:creator><![CDATA[GorbGorb]]></dc:creator><pubDate>Sat, 17 Dec 2011 18:49:11 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 19:01:20 GMT]]></title><description><![CDATA[<p>wxSkip schrieb:</p>
<blockquote>
<p>cooky451 schrieb:</p>
<blockquote>
<p>Nein, das ist ein klassischer Fall für verschiedene Funktionen. Das Template bringt hier nur Nachteile.</p>
</blockquote>
<p>Außer, er will es aus einem anderen Template heraus benutzen.</p>
</blockquote>
<p>Ok, dann ist eine Spezialisierung wie bei GorbGorb aber immer noch sinnvoller.</p>
<p>(Außer dass ich nicht ganz verstehe, warum er nicht gleich static_assert(false, ..) schreibt. ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158145</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 17 Dec 2011 19:01:20 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 19:18:02 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">struct Settings
{
    std::string str_data;
    int data;
};

Settings* findSetting(const std::string&amp;);

template &lt;typename T&gt; struct type2member;
template &lt;&gt; struct type2member&lt;int&gt;         : std::integral_constant&lt;int Settings::*, &amp;Settings::data&gt; {};
template &lt;&gt; struct type2member&lt;bool&gt;        : std::integral_constant&lt;int Settings::*, &amp;Settings::data&gt; {};
template &lt;&gt; struct type2member&lt;std::string&gt; : std::integral_constant&lt;std::string Settings::*, &amp;Settings::str_data&gt; {};

template &lt;typename T&gt;
T get(const std::string&amp; name)
{
     return findSetting(name)-&gt;*type2member&lt;T&gt;::value;
}

template &lt;typename T&gt;
void set(const std::string&amp; name, const T&amp; v)
{
    findSetting(name)-&gt;*type2member&lt;T&gt;::value = v;
}
</code></pre>
<p>Solange nicht noch extra Umwandlungen im Spiel sind, wird hier nur eine Zuordnung Typ-&gt;Member benötigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158147</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 17 Dec 2011 19:18:02 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 22:44:14 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>(Außer dass ich nicht ganz verstehe, warum er nicht gleich static_assert(false, ..) schreibt. ;))</p>
</blockquote>
<p>Weil der static_assert dann auch ausgelöst wird, wenn man gar nichts instanziert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158201</guid><dc:creator><![CDATA[GorbGorb]]></dc:creator><pubDate>Sat, 17 Dec 2011 22:44:14 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sat, 17 Dec 2011 22:48:22 GMT]]></title><description><![CDATA[<p>type_info ist hier ja mal sowas von falsch...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158202</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 17 Dec 2011 22:48:22 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 13:49:38 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>type_info ist hier ja mal sowas von falsch...</p>
</blockquote>
<p>Qualitativ hochwertiger Kommentar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Es gibt Gründe, warum ich die Spezialisierung von Template-Funktionen meide...<br />
Wenn Experten, die fast so viel Ahnung von C++ haben wie du <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="🙄"
    />, davon abraten, dann nehm ich mir das zu Herzen: <a href="http://www.gotw.ca/publications/mill17.htm" rel="nofollow">http://www.gotw.ca/publications/mill17.htm</a></p>
<p>Also halt einfach die Fresse, solange keiner &quot;Arsch öffne dich&quot; sagt oder begründe deine Ansichten...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158347</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 18 Dec 2011 13:49:38 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 14:02:13 GMT]]></title><description><![CDATA[<p>Weil du ein vollständig zur Kompilezeit bekanntes Problem zur Laufzeit erst löst. Sowas hätte selbst dir auffallen können, Schlaumeier.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158351</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Dec 2011 14:02:13 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 14:05:56 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>type_info ist hier ja mal sowas von falsch...</p>
</blockquote>
<p>314159265358979 schrieb:</p>
<blockquote>
<p>Weil du ein vollständig zur Kompilezeit bekanntes Problem zur Laufzeit erst löst. Sowas hätte selbst dir auffallen können, Schlaumeier.</p>
</blockquote>
<p>Wobei das eine nichts mit dem anderen zu tun hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158352</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 18 Dec 2011 14:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 14:06:38 GMT]]></title><description><![CDATA[<p>Blahblah, du weißt ganz genau wie's gemeint ist. Stell dich nicht dumm.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158353</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Dec 2011 14:06:38 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:15:53 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Weil du ein vollständig zur Kompilezeit bekanntes Problem zur Laufzeit erst löst. Sowas hätte selbst dir auffallen können, Schlaumeier.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>314159265358979 schrieb:</p>
<blockquote>
<p>Blahblah, du weißt ganz genau wie's gemeint ist. Stell dich nicht dumm.</p>
</blockquote>
<p>Ich jedenfalls stelle mich nicht dumm, sondern weiß wirklich nicht, wie es gemeint ist.</p>
<p>Wieso wird die type_info zur Laufzeit ausgewertet? (Ernst gemeinte Frage...)</p>
<p>Das assert statt Exception sehe ich absolut ein. Ich hab die Exception nur aus seinem Code übernommen ohne mir darüber Gedanken zu machen.<br />
Aber wenn man ein Vorgehen kritisiert und als Argument eine andere Sache nimmt, die nichts damit zu tun hat, dann stimmt irgendwas nicht.</p>
<p>Ich bin eigentlich fest davon überzeugt, dass die type_info zur Kompilierzeit ausgewertet wird, lasse mich aber gerne eines Besseren belehren.</p>
<p>Alles andere würde mich jedoch sehr wundern...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158416</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158416</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:15:53 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:33:03 GMT]]></title><description><![CDATA[<p>XSpille schrieb:</p>
<blockquote>
<p>Ich bin eigentlich fest davon überzeugt, dass die type_info zur Kompilierzeit ausgewertet wird, lasse mich aber gerne eines Besseren belehren.</p>
</blockquote>
<p>Der <code>typeid</code> -Operator ist Bestandteil von RTTI = <strong>Runtime</strong> Type Identification. Er wird schliesslich primär eingesetzt, um an den dynamischen Typen hinter Basisklassenverweisen zu kommen, welche per Definition erst zur Laufzeit feststehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158429</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:33:03 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:34:41 GMT]]></title><description><![CDATA[<p>Ach, ich sehe schon das Problem. Du hast deine Klasse dummerweise type_info genannt, worauf ich mir den Code nicht mehr genauer angesehen habe. Wer gibt seiner Klasse auch so einen Namen, wobei sie damit nicht mal ansatzweise was zu tun hat. Was du da verwendest, ist ein Type2Type von Alexandrescu, das passt schon so.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158432</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:34:41 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:35:35 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>XSpille schrieb:</p>
<blockquote>
<p>Ich bin eigentlich fest davon überzeugt, dass die type_info zur Kompilierzeit ausgewertet wird, lasse mich aber gerne eines Besseren belehren.</p>
</blockquote>
<p>Der <code>typeid</code> -Operator ist Bestandteil von RTTI = <strong>Runtime</strong> Type Identification. Er wird schliesslich primär eingesetzt, um an den dynamischen Typen hinter Basisklassenverweisen zu kommen, welche per Definition erst zur Laufzeit feststehen.</p>
</blockquote>
<p>type_info != std::type_info<br />
Der Name mag etwas ungünstig gewählt sein für ein tag, mit RTTI hat es jedenfalls nichts zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158435</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:35:35 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:39:04 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>XSpille schrieb:</p>
<blockquote>
<p>Ich bin eigentlich fest davon überzeugt, dass die type_info zur Kompilierzeit ausgewertet wird, lasse mich aber gerne eines Besseren belehren.</p>
</blockquote>
<p>Der <code>typeid</code> -Operator ist Bestandteil von RTTI = <strong>Runtime</strong> Type Identification. Er wird schliesslich primär eingesetzt, um an den dynamischen Typen hinter Basisklassenverweisen zu kommen, welche per Definition erst zur Laufzeit feststehen.</p>
</blockquote>
<p>Hi Nexus,<br />
das weiß ich.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/22268">@PI</a>: Geht deine Kritik an die typeid oder an das typeinfo-Template, das ich gepostet habe?</p>
<p>Ich dachte der Kommentar hatte sich auf das Template bezogen.</p>
<p>EDIT: OK, alle Unklarheiten beseitigt. Dann gebe ich dir absolut recht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158438</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:39:04 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:38:33 GMT]]></title><description><![CDATA[<p>2</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158439</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:38:33 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Sun, 18 Dec 2011 16:40:23 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>2</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Also doch an das Template? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158444</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 18 Dec 2011 16:40:23 GMT</pubDate></item><item><title><![CDATA[Reply to templates mit mehreren Rückgabe Typen on Mon, 19 Dec 2011 20:29:56 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich hab die Exception nur aus seinem Code übernommen ohne mir darüber Gedanken zu machen.</p>
</blockquote>
<p>nu ja möglicherweise ist die exception da nicht geeignet. Grundsätzlich soll diese mich schnell über einen Programmierfehler informieren. ich habe die komplette app in ein try gelegt.</p>
<p>also so:</p>
<pre><code class="language-cpp">#include &quot;main.h&quot;
#include &lt;QString&gt;
#include &lt;QApplication&gt;
#include &quot;app.h&quot;
#include &quot;exception.h&quot;

int main(int argc, char** argv) {
    QApplication app(argc, argv);
    app.setWindowIcon(QIcon(&quot;:/tmb.ico&quot;));

    QString app_style =
    &quot;QMenuBar::item {background-color: rgb(255,255,255);}&quot;
    &quot;QMenuBar::item:selected {border: 1px solid rgb(121,152,241);}&quot;
    &quot;QMenu::item {padding: 2px 25px 2px 20px;background: #FFFFFF;border: 1px solid transparent;}&quot;
    &quot;QMenu::item:selected  {border: 1px solid rgb(121,152,241);background-color: rgb(226,233,254);color: #000000;}&quot;
    &quot;QMenu::separator { width: 1px; height: 1px;}&quot;;

    app.setStyleSheet(app_style);

    QString app_dir = QApplication::applicationFilePath();
    app_dir = app_dir.left(app_dir.lastIndexOf( '/' ) + 1);

    try {
        return App(app, app_dir).Run();
    } catch (const Exception&amp; exception) {
        return exception.handle();
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2158973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158973</guid><dc:creator><![CDATA[PiCiJi]]></dc:creator><pubDate>Mon, 19 Dec 2011 20:29:56 GMT</pubDate></item></channel></rss>