[LC++]ambiguity, temporaries, const
Roberto Diaz
roberto at vivaldi.dhis.org
Mon Dec 31 06:47:05 UTC 2001
Hi!
The following code shows that under gcc 2.95
* Theres not ambiguity in f(P&) and f(const P&)
* Temporaries passed by reference default to const &
* Non-temporaries default to non-const
Is this g++ specificic? is there in the C++ standard?
#include <iostream>
using namespace std;
class P
{
};
class A
{
public:
void f (P &p) { cout << "non-const" << endl; }
void f (const P &p) { cout << "const" << endl; }
};
int
main ()
{
P p;
A a;
// why there is not ambiguity here?
a.f(p);
// temporary not problems neither?
a.f(P());
return 0;
}
Thank you!
--
Saludos
Roberto Díaz <roberto at vivaldi.dhis.org>
PLEASE HELP SAVE faqs.org!
http://www.faqs.org/save_faqs-org.html
More information about the tuxCPProgramming
mailing list