<?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[Unspeziifierte Anzahl an Argumenten]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich rufe:</p>
<pre><code class="language-cpp">template &lt;typename T&gt; T getMax(T firstArg, ...)
{
  va_list ap;
  va_start(ap, firstArg);

  T max = firstArg;
  while (true)
  {
    T* arg = va_arg(ap, T*);
    if (arg == 0) break;
    if (*arg &gt; max) max = *arg;
  }

  va_end(ap);

  return max;
}
</code></pre>
<p>mit</p>
<pre><code class="language-cpp">double max = getMax&lt;double&gt;(a1, a2, a3);
</code></pre>
<p>auf.</p>
<p>Kompiliert super, funktioniert aber leider nicht.<br />
getMax gibt immer nur firstArg zurück. Die Schleife wird sofort per break verlassen.<br />
Weiß jemand wieso?<br />
Ich benutze den DevC++.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123876/unspeziifierte-anzahl-an-argumenten</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 18:31:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123876.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 20 Oct 2005 23:18:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unspeziifierte Anzahl an Argumenten on Thu, 20 Oct 2005 23:18:15 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich rufe:</p>
<pre><code class="language-cpp">template &lt;typename T&gt; T getMax(T firstArg, ...)
{
  va_list ap;
  va_start(ap, firstArg);

  T max = firstArg;
  while (true)
  {
    T* arg = va_arg(ap, T*);
    if (arg == 0) break;
    if (*arg &gt; max) max = *arg;
  }

  va_end(ap);

  return max;
}
</code></pre>
<p>mit</p>
<pre><code class="language-cpp">double max = getMax&lt;double&gt;(a1, a2, a3);
</code></pre>
<p>auf.</p>
<p>Kompiliert super, funktioniert aber leider nicht.<br />
getMax gibt immer nur firstArg zurück. Die Schleife wird sofort per break verlassen.<br />
Weiß jemand wieso?<br />
Ich benutze den DevC++.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897279</guid><dc:creator><![CDATA[Argument]]></dc:creator><pubDate>Thu, 20 Oct 2005 23:18:15 GMT</pubDate></item><item><title><![CDATA[Reply to Unspeziifierte Anzahl an Argumenten on Fri, 21 Oct 2005 06:47:22 GMT]]></title><description><![CDATA[<p><a href="http://man.cx/va_arg" rel="nofollow">man: va_arg</a> liefert keinen Pointer auf das jeweilige Element, sondern das Element selber. Also sollte es richtiger heißen:</p>
<pre><code class="language-cpp">while (true)
{
    T arg = va_arg(ap, T);
    if (arg == T()) break;
    if (arg &gt; max) max = arg;
}
</code></pre>
<p>Und du mußt als Abbruchbedingung als letztes Element eine 0 in deinen Aufruf schreiben (in deiner variablen Argumentliste muß die Information stehen, wo die Argumente zu Ende sind, va_arg() würde dir sonst Pseudo-Argumente liefern, bis es an die Stack-Grenzen kracht).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897351</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 21 Oct 2005 06:47:22 GMT</pubDate></item><item><title><![CDATA[Reply to Unspeziifierte Anzahl an Argumenten on Fri, 21 Oct 2005 07:37:11 GMT]]></title><description><![CDATA[<p>warum machst du nicht ne std::list oder std::vector mit den Werten und übergibst sie?</p>
<p>Variable Argumentenlisten sind unter C++ sehr sehr unerwünscht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897389</guid><dc:creator><![CDATA[.................]]></dc:creator><pubDate>Fri, 21 Oct 2005 07:37:11 GMT</pubDate></item><item><title><![CDATA[Reply to Unspeziifierte Anzahl an Argumenten on Fri, 21 Oct 2005 10:39:57 GMT]]></title><description><![CDATA[<p>oder wieso übergibst du nicht einfach 2 iteratoren?</p>
<pre><code class="language-cpp">template &lt;typename Iterator&gt; 
Iterator getMax(Iterator pos, Iterator end)
{
  Iterator max=pos;
  while (pos!=end)
  {
    if (*pos &gt; *max) max = *pos;
    ++pos;
  }
  return max;
}
</code></pre>
<p>musst du dann so aufrufen:</p>
<pre><code class="language-cpp">std::vector&lt;double&gt; vec;
//füllen...
vec.push_back(3.3);
vec.push_back(5.37);
vec.push_back(7);
vec.push_back(18.356);
vec.push_back(9.238);

double max=*getMax(vec.begin(),vec.end());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/897610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897610</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Fri, 21 Oct 2005 10:39:57 GMT</pubDate></item></channel></rss>