Topic: references in overloaded functions


Author: Dominique Marcadet <Dominique.Marcadet@supelec.fr>
Date: 1995/09/28
Raw View
In the DWP, in over.load, there is a list of cases where parameter
declarations are considered equivalents for the purpose of overloading
resolution.
I don't see anything about parameter declarations that differ only in the
use of references.

Does it mean that
   void f (int) { ... }
   void f (int &) { ... }
is legal C++ code (but which one will be used ?), does I have missed
something, or is it an omission of the DWP ?

Dominique Marcadet

+------------------------------------------------------------------------+
| Service Informatique Supelec         |  Dominique.Marcadet@supelec.fr  |
| Plateau de Moulon                    |  Tel : +33 1 69 85 14 73        |
| 91192 Gif sur Yvette Cedex - France  |  Fax : +33 1 69 85 12 34        |




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/09/29
Raw View
In article 95Sep28101336@physics2.Berkeley.EDU, Dominique Marcadet <Dominique.Marcadet@supelec.fr> writes:
>
>In the DWP, in over.load, there is a list of cases where parameter
>declarations are considered equivalents for the purpose of overloading
>resolution.
>I don't see anything about parameter declarations that differ only in the
>use of references.
>
>Does it mean that
>   void f (int) { ... }
>   void f (int &) { ... }

Right, these are two different functions and the prototypes are not equivalent.

>is legal C++ code (but which one will be used ?), does I have missed
>something, or is it an omission of the DWP ?

It is legal to declare both functions, but an attempt to call one if both
are in scope is likely to result in an ambiguity.

The usual rule in C++ is that a potential ambiguity is not an error;
only an actual ambiguity, in this case at the point of a call, is an error.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]