Article View: comp.std.c++
Article #3709Re: Static member functions and overloading resolution
From: Steve Clamage
Date: Mon, 18 Mar 1996 17:38
Date: Mon, 18 Mar 1996 17:38
42 lines
2263 bytes
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
]
Technical Details
Message-ID:
<4ifv63$qsk@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<4i9rbn$fgj@cri.ens-lyon.fr>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Static member functions and overloading resolution Date: 18 Mar 1996 09:38:16 PST Organization: Sun Microsystems Inc., Mountain View, CA Approved: austern@isolde.mti.sgi.com Message-ID: <4ifv63$qsk@engnews1.Eng.Sun.COM> References: <4i9rbn$fgj@cri.ens-lyon.fr> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 17 Mar 1996 02:59:15 GMT X-Newsreader: NN version 6.5.0 #21 (NOV) X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMU2fsEy4NqrwXLNJAQGJVAIAzN4fvIiF8ISkyre7m9e9eY1Rr/RWJQb7 ieJDpIXBrK2vv21SJr10pqiHKMxLgEu4dP84jeVjiabCer6bfG0ExQ== =d89M Originator: austern@isolde.mti.sgi.com