[LC++]ambiguity, temporaries, const

Davide Bolcioni 9odb6x3rfr001 at sneakemail.com
Sun Jan 6 05:50:05 UTC 2002


Roberto Diaz roberto at vivaldi.dhis.org [mltuxcpp/linux-cpp list] wrote:


> What I actually was trying to mean is that for instance if I overload this way:
> 
> (I really was trying to pass temporaries and non-temporaries to the same
> function (name) without the use of pointers)
> 
> void f (P&); 
> void f (P);
> 
> I get errors.. I suppose it is not possible to overload this way..


This is a separate issue. If you have:


   void f(P&) { cout << "By reference\n"; }
   void f(P) { cout << "By value\n" ; }

which should the compiler use when it sees:

   P p;

   f(p); // Which one ?

Note that the compiler is able to sort out:

   P const cp;

   f(cp);

because the qualification rules say that void f(P&)
cannot be called on a P const, only on non-const non-volatile
P.

Davide Bolcioni
-- 
There is no place like /home.




More information about the tuxCPProgramming mailing list