Topic: Static member functions and overloading resolution


Author: elesueur@ens-lyon.fr (Emmanuel Lesueur)
Date: 1996/03/15
Raw View
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                             ]





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1996/03/18
Raw View
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
]





Author: elesueur@ens-lyon.fr (Emmanuel Lesueur)
Date: 1996/03/18
Raw View
In article <4ifv63$qsk@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM (Steve Clamage) writes:
>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.

Oops... You're right, of course. I swapped the function parameters.
What about:

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

> class B : public A {
> };

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

Is this ambiguous ? As I understand it, the draft paper says yes.
(gcc says no.)

___________________________________________________

Emmanuel Lesueur  -   elesueur@ens-lyon.fr




[ 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
]