<?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[Implizite Typumwandlung im Methodenaufruf]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich versuche gerade nachzuvollziehen, wie die implizite Typumwandlung in C++ funktioniert. Dazu habe ich mir folgendes Testprogramm aufgebaut:</p>
<pre><code>#include &lt;iostream.h&gt;
class A
{public:
		void typ(char x, char y, char z) {cout&lt;&lt;&quot;CCC&quot;&lt;&lt;endl;}
		void typ(char x, char y, float z) {cout&lt;&lt;&quot;CCF&quot;&lt;&lt;endl;}
		void typ(int x, float y, float z) {cout&lt;&lt;&quot;IFF&quot;&lt;&lt;endl;}
		void typ(float x, char y, float z) {cout&lt;&lt;&quot;FCF&quot;&lt;&lt;endl;}
		void typ(int x, int y, int z) {cout&lt;&lt;&quot;III&quot;&lt;&lt;endl;}};
int main()
{	char s='e'; int i=3; float f=4; A a;
	a.typ(s,s,s); //1
	a.typ(s,f,f); //2
	a.typ(f,f,f); //3
	a.typ(i,s,f); //4
	a.typ(f,i,s); //5
	a.typ(f,f,i); //6
	a.typ(s,i,f); //7
	a.typ(f,s,i); //8
	a.typ(s,i,i); //9
	a.typ(s,f,i); //10}
</code></pre>
<p>Ergebnis: Nur der erste Aufruf mit s,s,s wird akzeptiert. Alle anderen rufen eine Fehlermeldung hervor (&quot;call of overloaded 'typ...' is ambiguous&quot;)<br />
Meiner Meinung nach müssten aber Aufruf 4, 8 und 10 ebenfalls klappen.</p>
<p>Kann mit jemand erklären, wo mein Denkfehler liegt?</p>
<p>Vielen Dank im Voraus!<br />
Philip</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/223662/implizite-typumwandlung-im-methodenaufruf</link><generator>RSS for Node</generator><lastBuildDate>Sat, 03 Oct 2026 19:19:09 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/223662.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Sep 2008 11:31:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Implizite Typumwandlung im Methodenaufruf on Mon, 29 Sep 2008 11:31:03 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich versuche gerade nachzuvollziehen, wie die implizite Typumwandlung in C++ funktioniert. Dazu habe ich mir folgendes Testprogramm aufgebaut:</p>
<pre><code>#include &lt;iostream.h&gt;
class A
{public:
		void typ(char x, char y, char z) {cout&lt;&lt;&quot;CCC&quot;&lt;&lt;endl;}
		void typ(char x, char y, float z) {cout&lt;&lt;&quot;CCF&quot;&lt;&lt;endl;}
		void typ(int x, float y, float z) {cout&lt;&lt;&quot;IFF&quot;&lt;&lt;endl;}
		void typ(float x, char y, float z) {cout&lt;&lt;&quot;FCF&quot;&lt;&lt;endl;}
		void typ(int x, int y, int z) {cout&lt;&lt;&quot;III&quot;&lt;&lt;endl;}};
int main()
{	char s='e'; int i=3; float f=4; A a;
	a.typ(s,s,s); //1
	a.typ(s,f,f); //2
	a.typ(f,f,f); //3
	a.typ(i,s,f); //4
	a.typ(f,i,s); //5
	a.typ(f,f,i); //6
	a.typ(s,i,f); //7
	a.typ(f,s,i); //8
	a.typ(s,i,i); //9
	a.typ(s,f,i); //10}
</code></pre>
<p>Ergebnis: Nur der erste Aufruf mit s,s,s wird akzeptiert. Alle anderen rufen eine Fehlermeldung hervor (&quot;call of overloaded 'typ...' is ambiguous&quot;)<br />
Meiner Meinung nach müssten aber Aufruf 4, 8 und 10 ebenfalls klappen.</p>
<p>Kann mit jemand erklären, wo mein Denkfehler liegt?</p>
<p>Vielen Dank im Voraus!<br />
Philip</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1590181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1590181</guid><dc:creator><![CDATA[PhilipM]]></dc:creator><pubDate>Mon, 29 Sep 2008 11:31:03 GMT</pubDate></item><item><title><![CDATA[Reply to Implizite Typumwandlung im Methodenaufruf on Mon, 29 Sep 2008 11:41:50 GMT]]></title><description><![CDATA[<p>PhilipM schrieb:</p>
<blockquote>
<p>Meiner Meinung nach müssten aber Aufruf 4, 8 und 10 ebenfalls klappen.</p>
</blockquote>
<p>Ich sehe jetzt keinen Grund warum 4,8 und 10 funktionieren sollten - Es muss auf jedenfall mindestens eine Umwandlung gemacht werden, und dann ist immer die Frage: welche Funktion soll genommen werden?</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1590188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1590188</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 29 Sep 2008 11:41:50 GMT</pubDate></item><item><title><![CDATA[Reply to Implizite Typumwandlung im Methodenaufruf on Mon, 29 Sep 2008 12:24:12 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
void foo(char,  char,  char)  { std::cout &lt;&lt; &quot;CCC\n&quot;; }
void foo(char,  char,  float) { std::cout &lt;&lt; &quot;CCF\n&quot;; } 
void foo(int,   float, float) { std::cout &lt;&lt; &quot;IFF\n&quot;; }
void foo(float, char,  float) { std::cout &lt;&lt; &quot;FCF\n&quot;; }
void foo(int,   int,   int)   { std::cout &lt;&lt; &quot;III\n&quot;; }

int main()
{
    char c='e';
    int i=3;
    float f=4;
// 0 = exact match
// 1 = promotion ( char-&gt;int )
// 2 = conversion ( char-&gt;float, int-&gt;float, float-&gt;char, float-&gt;int )
    foo( c, c, c ); //  1 CCC(000) ccf(002) iff(122) fcf(202) iii(111)
    foo( c, f, f ); //  2 CCC(022) CCF(020) IFF(100) FCF(220) III(122)
    foo( f, f, f ); //  3 ccc(222) ccf(220) IFF(200) FCF(020) iii(222)
    foo( i, c, f ); //  4 CCC(202) CCF(200) IFF(020) FCF(200) III(012)
    foo( f, i, c ); //  5 CCC(220) CCF(222) IFF(222) FCF(022) III(201)
    foo( f, f, i ); //  6 ccc(222) ccf(222) IFF(202) FCF(022) III(220)
    foo( c, i, f ); //  7 CCC(022) CCF(020) IFF(120) FCF(220) III(102)
    foo( f, c, i ); //  8 CCC(202) CCF(202) iff(222) FCF(002) III(210)
    foo( c, i, i ); //  9 CCC(022) CCF(022) iff(122) fcf(222) III(100)
    foo( c, f, i ); // 10 CCC(022) CCF(022) IFF(102) fcf(222) III(120)
}
</code></pre>
<p>Eine Überladung ist besser als eine andere Überladung für ein gegebenes Argumenttupel, wenn der Konvertierungsrang für kein Argument schlechter (also wie oben definiert numerisch größer) als der Rang für dieses Argument für die andere Überladung ist, und der Rang für wenigstens ein Argument besser ist. Mithin sind oben alle möglichen Kombinationen mit Konvertierungsrang angegeben. Die jeweilige Überladung wird klein geschrieben, wenn sie schlechter als alle großgeschriebenen Überladungen ist. Eine Mehrdeutigkeit besteht immer dann, wenn mehr als eine Überladung groß geschrieben werden muss - dann gibt es mehrere &quot;beste&quot; Überladungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1590215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1590215</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 29 Sep 2008 12:24:12 GMT</pubDate></item><item><title><![CDATA[Reply to Implizite Typumwandlung im Methodenaufruf on Mon, 29 Sep 2008 12:16:59 GMT]]></title><description><![CDATA[<p>Genau - eine Umwandlung muss gemacht werden. Allerdings kann ja z.B. von float keine implizite Umwandlung auf int geschehen. Implizite Umwandlung heißt doch, dass ich z.B. schreiben kann:</p>
<pre><code>char c = 'e';
int i = c;
</code></pre>
<p>c wird dann auf int &quot;erweitert&quot;.</p>
<p>Jetzt zurück zum Beispiel: In Aufruf 8 (f,s,i) kann i nach float geweitet werden, so dass die vierte Überladung von &quot;typ&quot; passt. Bei allen anderen Überladungen ist es jedoch nicht möglich - also keine Zweideutigkeit. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1590217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1590217</guid><dc:creator><![CDATA[PhilipM]]></dc:creator><pubDate>Mon, 29 Sep 2008 12:16:59 GMT</pubDate></item><item><title><![CDATA[Reply to Implizite Typumwandlung im Methodenaufruf on Mon, 29 Sep 2008 12:22:50 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@camper</a>: Vielen Dank für die ausführliche Antwort. Mir war nicht klar, dass C++ einen solchen Vergleich anstellt. Bin davon ausgegangen, dass eine Überladung auch dann auf jeden Fall besser ist als eine andere, wenn sie weniger Typumwandlungen durchführt als die andere.</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1590222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1590222</guid><dc:creator><![CDATA[PhilipM]]></dc:creator><pubDate>Mon, 29 Sep 2008 12:22:50 GMT</pubDate></item></channel></rss>