This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Default parameters - problems
- From: John Love-Jensen <eljay at adobe dot com>
- To: anitha boyapati <anitha dot boyapati at gmail dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Mon, 18 Jun 2007 09:01:40 -0500
- Subject: 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