🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Emmanuel Lesueur Fri, 15 Mar 1996 00:48
Static member functions and overloading resolution
#3679
Author: Emmanuel Lesueur
Date: Fri, 15 Mar 1996 00:48
39 lines
1903 bytes
Consider the following situation:

	class A {
	public:
		void f(int);
		static void f(char);
	};

	class B : public A {
	};

	void foo(B& b,char c) {
		b.f(c);
	}

Here, the candidates functions for overloading resolution are
f(const A&,int) and f(?,char) where '?' matches any type,
and the call arguments have types B& and char.
The first candidate needs a conversion from B& to const A& for the
first argument while the second is an exact match. The second
candidate has an exact match for the first argument while the
second requires a char->int promotion. Therefore, the call
is ambiguous.

Is the above correct, or did I miss something ?
If I understood correctly, is this the intended behaviour ? 
If so, why ? 
I think selecting f(char) would make more sense here (and that's
what the compilers I have tested do).

___________________________________________________

Emmanuel Lesueur  -   elesueur@ens-lyon.fr
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: Static member functions and overloading resolution
#3709
Author: Steve Clamage
Date: Mon, 18 Mar 1996 17:38
42 lines
2263 bytes
elesueur@ens-lyon.fr (Emmanuel Lesueur) writes:

>Consider the following situation:

>	class A {
>	public:
>		void f(int);
>		static void f(char);
>	};

>	class B : public A {
>	};

>	void foo(B& b,char c) {
>		b.f(c);
>	}

>Here, the candidates functions for overloading resolution are
>f(const A&,int) and f(?,char) where '?' matches any type,
>and the call arguments have types B& and char.
>The first candidate needs a conversion from B& to const A& for the
>first argument while the second is an exact match. The second
>candidate has an exact match for the first argument while the
>second requires a char->int promotion. Therefore, the call
>is ambiguous.

According to the way you wrote your example, the first
candidate is the non-static f(int). It requires a conversion
from B& to A& on the first argument, and a promotion of char
to int on the second. The second candidate, static f(char), has
an exact match on any first argument (since it is a fiction anyway),
and an exact match (char to char) on the second argument.
There is no ambiguity, and the static f(char) should be selected.
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads