Default parameters - problems
John Love-Jensen
eljay@adobe.com
Mon Jun 18 15:06:00 GMT 2007
Hi Anitha,
> Why is this not compiling ?
Because the code is ambiguous as to which func1 should be used.
> Can somebody explain what is going on here ?
The code is ambiguous, and the compiler cannot guess as to which func1 is
desired.
> Why is it not directly going to overloaded func1 () - declared second. ?
Because the signatures of the parameters do not match the second func1 any
better than the first func1.
There are three ways you can fix your source code:
1. change the 'string' parameters to 'const char*' parameters.
2. change the calling parameters from const char[] literals (the "hello" and
"world"), to string objects instead.
t->func1(string("hello"), string("world"), false);
3. Use different method names instead of overloading func1 with two
different sets of parameters.
Also a point of style: don't do "using namespace" in the global scope of
header files. (I'd even go a step further and strongly recommend never
doing "using namespace" anywhere in header files; but I'm draconian that
way.)
HTH,
--Eljay
More information about the Gcc-help
mailing list