This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Default parameters - problems


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]