<?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[Überladungsproblem]]></title><description><![CDATA[<p>Hi,</p>
<p>Wieso ist hier unbedingt eine explizite Typumwandlung notwendig?:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

unsigned int umfang(unsigned int a, unsigned int b)
{
    return((2 * a) + (2 * b));
}

float umfang(float a, float b)
{
    return((2 * a) + (2 * b));
}

int main(void)
{
    cout &lt;&lt; &quot;a = 3, b = 7, Umfang: &quot; &lt;&lt; umfang((unsigned int)3, (unsigned int)7) &lt;&lt; endl;
    cout.precision(2);
    cout &lt;&lt; fixed &lt;&lt; &quot;a = 3.5, b = 1.5, Umfang: &quot; &lt;&lt; umfang((float)3.5, (float)1.5) &lt;&lt; endl;

    return(0);
}
</code></pre>
<p>Ohne die explizite Typumwandlung bekomm ich die Meldung:<br />
call of overloaded 'umfang(double, double)' is ambiguous</p>
<p>lg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/288260/überladungsproblem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 02:19:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/288260.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Jun 2011 13:53:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überladungsproblem on Mon, 13 Jun 2011 13:53:28 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Wieso ist hier unbedingt eine explizite Typumwandlung notwendig?:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

unsigned int umfang(unsigned int a, unsigned int b)
{
    return((2 * a) + (2 * b));
}

float umfang(float a, float b)
{
    return((2 * a) + (2 * b));
}

int main(void)
{
    cout &lt;&lt; &quot;a = 3, b = 7, Umfang: &quot; &lt;&lt; umfang((unsigned int)3, (unsigned int)7) &lt;&lt; endl;
    cout.precision(2);
    cout &lt;&lt; fixed &lt;&lt; &quot;a = 3.5, b = 1.5, Umfang: &quot; &lt;&lt; umfang((float)3.5, (float)1.5) &lt;&lt; endl;

    return(0);
}
</code></pre>
<p>Ohne die explizite Typumwandlung bekomm ich die Meldung:<br />
call of overloaded 'umfang(double, double)' is ambiguous</p>
<p>lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077467</guid><dc:creator><![CDATA[Jeffson]]></dc:creator><pubDate>Mon, 13 Jun 2011 13:53:28 GMT</pubDate></item><item><title><![CDATA[Reply to Überladungsproblem on Mon, 13 Jun 2011 14:04:32 GMT]]></title><description><![CDATA[<p>Weil die Regeln zur impliziten Konvertierung eingebauter Typen definiert sind. Wenn du hingegen die Parametertypen auf <code>int</code> und <code>double</code> setzt, dann nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077473</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:04:32 GMT</pubDate></item><item><title><![CDATA[Reply to Überladungsproblem on Mon, 13 Jun 2011 14:03:26 GMT]]></title><description><![CDATA[<p>Afaik weil der Compiler sonst nicht weiss, ob er die Zahl als unsigned int oder als float interpretieren soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077476</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:03:26 GMT</pubDate></item><item><title><![CDATA[Reply to Überladungsproblem on Mon, 13 Jun 2011 14:15:56 GMT]]></title><description><![CDATA[<p>Tipp: Auch Literale haben einen Typ und diesen kann man auch ändern:</p>
<pre><code>0     int
0U    unsigned int
0L    long
0 UL  unsigned long
0.    double
0.f   float
0.L   long double
</code></pre>
<p>Und noch mehr Kombinationen, alternative Schreibweisen und ein paar Sonderregeln für char, die ich jetzt nicht alle hinschreiben möchte.</p>
<p>Damit kannst du dann <code>umfang(3U, 7U)</code> schreiben und das funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077488</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:15:56 GMT</pubDate></item></channel></rss>