<?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[Typ eines vectors abfragen]]></title><description><![CDATA[<p>Hi,</p>
<p>in meinem Program arbeite ich nur mit vectoren aber an enigen Stellen muss ich mit einer externen API arbeiten, das sieht dann so aus:</p>
<pre><code>std::vector&lt;int&gt;vec;
allocate(....,vec.size()*sizeof(int),...);
</code></pre>
<p>Wenn ich jetzt den Vector von int zu double andere muss ich auch immer den sizeof parameter aendern:</p>
<pre><code>std::vector&lt;double&gt;vec;
allocate(....,vec.size()*sizeof(double),...);
</code></pre>
<p>Gib es einen Mechanismus um das automatisch zu machen, also den Typ eies Vectors erfragen?</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/322016/typ-eines-vectors-abfragen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 13:53:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322016.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Dec 2013 12:44:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 12:44:11 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>in meinem Program arbeite ich nur mit vectoren aber an enigen Stellen muss ich mit einer externen API arbeiten, das sieht dann so aus:</p>
<pre><code>std::vector&lt;int&gt;vec;
allocate(....,vec.size()*sizeof(int),...);
</code></pre>
<p>Wenn ich jetzt den Vector von int zu double andere muss ich auch immer den sizeof parameter aendern:</p>
<pre><code>std::vector&lt;double&gt;vec;
allocate(....,vec.size()*sizeof(double),...);
</code></pre>
<p>Gib es einen Mechanismus um das automatisch zu machen, also den Typ eies Vectors erfragen?</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369530</guid><dc:creator><![CDATA[PunktPubkt]]></dc:creator><pubDate>Tue, 03 Dec 2013 12:44:11 GMT</pubDate></item><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 12:49:46 GMT]]></title><description><![CDATA[<p>Was heisst hier abfragen? So wie du es beschreibst sieht es aus als wäre der Typ des Vektors at compile time bekannt.</p>
<pre><code>typedef	std::vector&lt;int&gt; intVec;
typedef	std::vector&lt;double&gt; doubleVec;
typedef doubleVec myVec;
std::cout &lt;&lt; sizeof(myVec::value_type) &lt;&lt; std::endl;
</code></pre>
<p>Oder was genau suchst du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369532</guid><dc:creator><![CDATA[Dobi]]></dc:creator><pubDate>Tue, 03 Dec 2013 12:49:46 GMT</pubDate></item><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 13:03:00 GMT]]></title><description><![CDATA[<p><code>sizeof(*vec.data())</code></p>
<p>~Edit: Frage gelöscht. sizeof() passiert ja zu compile-time. Dann sollte auch sizeof(vec[0]) OK sein.~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369533</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Tue, 03 Dec 2013 13:03:00 GMT</pubDate></item><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 13:03:03 GMT]]></title><description><![CDATA[<p>Dobi schrieb:</p>
<blockquote>
<p>Was heisst hier abfragen? So wie du es beschreibst sieht es aus als wäre der Typ des Vektors at compile time bekannt.</p>
<pre><code>typedef	std::vector&lt;int&gt; intVec;
typedef	std::vector&lt;double&gt; doubleVec;
typedef doubleVec myVec;
std::cout &lt;&lt; sizeof(myVec::value_type) &lt;&lt; std::endl;
</code></pre>
<p>Oder was genau suchst du?</p>
</blockquote>
<p>Ja genau das suche ich, aber wieso geht das jetzt hier nicht:</p>
<pre><code>#include &lt;vector&gt;

int main()
{
   std::vector&lt;int&gt;vec;
   vec::value_type;

   return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369534</guid><dc:creator><![CDATA[PunktPubkt]]></dc:creator><pubDate>Tue, 03 Dec 2013 13:03:03 GMT</pubDate></item><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 13:04:17 GMT]]></title><description><![CDATA[<p>Caligulaminus schrieb:</p>
<blockquote>
<p><code>sizeof(*vec.data())</code></p>
<p>~Edit: Frage gelöscht. sizeof() passiert ja zu compile-time. Dann sollte auch sizeof(vec[0]) OK sein.~</p>
</blockquote>
<p>Echt das darf man machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369535</guid><dc:creator><![CDATA[PunktPubkt]]></dc:creator><pubDate>Tue, 03 Dec 2013 13:04:17 GMT</pubDate></item><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 13:05:45 GMT]]></title><description><![CDATA[<blockquote>
<p>Ja genau das suche ich, aber wieso geht das jetzt hier nicht:</p>
</blockquote>
<p>Weil <code>vec</code> kein Typ ist, sondern ein Objekt. Stattdessen (mit C++11):</p>
<pre><code>decltype(vec)::value_type;
</code></pre>
<p>PunktPubkt schrieb:</p>
<blockquote>
<p>Echt das darf man machen?</p>
</blockquote>
<p>Ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369536</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369536</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 03 Dec 2013 13:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to Typ eines vectors abfragen on Tue, 03 Dec 2013 13:17:57 GMT]]></title><description><![CDATA[<p>Du kannst übrigens auch einfach<br />
vec.data() verwenden oder &amp;vec[0]<br />
wenn du ein array aus dem vector machen willst. dazu musst du nicht umkopieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369538</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Tue, 03 Dec 2013 13:17:57 GMT</pubDate></item></channel></rss>