<?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[Verwendung von decltype]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich wollte eigentlich folgendes schreiben:</p>
<pre><code>auto anz = anzRecords(), count = 0;
</code></pre>
<p>da merkert aber mein Visual Studio 2010, dass count den Typ int erhalten soll.</p>
<p>Ich will erreichen das die Variable count denselben Typ erhält wie anz.</p>
<p>Mir ist jetzt folgende Lösung eingefallen.</p>
<pre><code>auto anz = anzRecords();
decltype(anz) records = 0;
</code></pre>
<p>ist das so ok und üblich?</p>
<p>Gruss Uwe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/323236/verwendung-von-decltype</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 09:14:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/323236.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Jan 2014 09:28:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verwendung von decltype on Wed, 22 Jan 2014 09:28:57 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich wollte eigentlich folgendes schreiben:</p>
<pre><code>auto anz = anzRecords(), count = 0;
</code></pre>
<p>da merkert aber mein Visual Studio 2010, dass count den Typ int erhalten soll.</p>
<p>Ich will erreichen das die Variable count denselben Typ erhält wie anz.</p>
<p>Mir ist jetzt folgende Lösung eingefallen.</p>
<pre><code>auto anz = anzRecords();
decltype(anz) records = 0;
</code></pre>
<p>ist das so ok und üblich?</p>
<p>Gruss Uwe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378903</guid><dc:creator><![CDATA[uwe00]]></dc:creator><pubDate>Wed, 22 Jan 2014 09:28:57 GMT</pubDate></item><item><title><![CDATA[Reply to Verwendung von decltype on Wed, 22 Jan 2014 09:38:06 GMT]]></title><description><![CDATA[<p>Es ist gültiger Code und macht das was du möchtest. Ob es üblich ist weiß ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378905</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 22 Jan 2014 09:38:06 GMT</pubDate></item><item><title><![CDATA[Reply to Verwendung von decltype on Wed, 22 Jan 2014 10:15:20 GMT]]></title><description><![CDATA[<p>Vielleicht willste</p>
<pre><code>declytype(anzRecords()) anz = anzRecords(), count = 0;
</code></pre>
<p>Keine Ahnung, das Problem hatte ich noch nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378907</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 22 Jan 2014 10:15:20 GMT</pubDate></item><item><title><![CDATA[Reply to Verwendung von decltype on Wed, 22 Jan 2014 10:07:58 GMT]]></title><description><![CDATA[<p>uwe00 schrieb:</p>
<blockquote>
<p>da merkert aber mein Visual Studio 2010, dass count den Typ int erhalten soll.</p>
</blockquote>
<p>AFAIK müssen die Typen konsistent deduziert werden. Also, entweder kommt bei beiden int (oder sonstwas) raus, oder du musst das anders aufschreiben.</p>
<p>uwe00 schrieb:</p>
<blockquote>
<pre><code>auto anz = anzRecords();
decltype(anz) records = 0;
</code></pre>
</blockquote>
<p>So kann man das machen, ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378908</guid><dc:creator><![CDATA[kkaw]]></dc:creator><pubDate>Wed, 22 Jan 2014 10:07:58 GMT</pubDate></item><item><title><![CDATA[Reply to Verwendung von decltype on Wed, 22 Jan 2014 11:33:37 GMT]]></title><description><![CDATA[<p>[code=&quot;java&quot;]</p>
<blockquote>
<p>AFAIK müssen die Typen konsistent deduziert werden.</p>
</blockquote>
<p>Nö. Da sind unterschiedliche Prinzipien am Werk. Mal ein gekünsteltes Beispiel:<br />
[code=&quot;cpp&quot;]#include &lt;type_traits&gt;</p>
<p>int&amp;&amp; foo(){ return {}; } // Nur für Testzwecke</p>
<p>int main()<br />
{<br />
auto i = foo;<br />
decltype(foo) i2 /* = foo */;</p>
<p>static_assert( std::is_same&lt;decltype(i), int&amp;&amp;(*)()&gt;::value, &quot;&quot; );<br />
static_assert( std::is_same&lt;decltype(i2), int&amp;&amp;()&gt;::value, &quot;&quot; );<br />
}[/code]</p>
<blockquote>
<p>da merkert aber mein Visual Studio 2010, dass count den Typ int erhalten soll.</p>
</blockquote>
<p>Ja, weil der <code>auto</code> Typ-spezifizierer eben keine unterschiedlichen Typen deduzieren darf.</p>
<p>§ 7.1.6.4/8 schrieb:</p>
<blockquote>
<p>The type of each declared variable is determined as described above, and if the type that replaces the placeholder type is not the same in each deduction, the program is ill-formed.</p>
</blockquote>
<blockquote>
<p>ist das so ok und üblich?</p>
</blockquote>
<p>Ok und üblich ist es, in diesem Fall (für 0) einfach den Typ auszuschreiben.</p>
<pre><code>DerTyp anz = anzRecords(), count = 0;
</code></pre>
<p>Edit: Volkards Variante ist natürlich genauso möglich, ich finde aber, dass sie hier nicht schöner ist als das Ausschreiben des Typs.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378916</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 22 Jan 2014 11:33:37 GMT</pubDate></item><item><title><![CDATA[Reply to Verwendung von decltype on Wed, 22 Jan 2014 11:32:24 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Vielleicht willste</p>
<pre><code>declytype(anzRecords()) anz = anzRecords(), count = 0;
</code></pre>
<p>Keine Ahnung, das Problem hatte ich noch nicht.</p>
</blockquote>
<p>Danke, ich habe kein Problem mit zwei Zeilen Code, so sah es nur so ungewohnt aus.</p>
<p>Gruss Uwe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378917</guid><dc:creator><![CDATA[uwe00]]></dc:creator><pubDate>Wed, 22 Jan 2014 11:32:24 GMT</pubDate></item></channel></rss>