A
Alan Johnson
Consider the following code, with the interesting lines numbered in
comments:
class A
{
public :
bool f(int level = 1) // line 5
{ return true ; }
void f(bool val, int level = 1)
{}
} ;
class B
{
private :
A *a ;
public :
bool f(int level = 1) // line 18
{ return a->f(level) ; } // line 19
void f(bool val, int level = 1)
{ a->f(val, level) ; }
} ;
This compiles fine for me (gcc 3.4.4). However, if I make the functions
on line 5 and line 18 const, then my compiler says the function call on
line 19 is ambiguous. It makes sense to me why it would be ambiguous
(level is convertible to bool, and so it might could match f(bool, int)
since the int parameter has a default value). However, what I don't
understand is why it is NOT ambiguous without the const. Any insight?
-Alan
comments:
class A
{
public :
bool f(int level = 1) // line 5
{ return true ; }
void f(bool val, int level = 1)
{}
} ;
class B
{
private :
A *a ;
public :
bool f(int level = 1) // line 18
{ return a->f(level) ; } // line 19
void f(bool val, int level = 1)
{ a->f(val, level) ; }
} ;
This compiles fine for me (gcc 3.4.4). However, if I make the functions
on line 5 and line 18 const, then my compiler says the function call on
line 19 is ambiguous. It makes sense to me why it would be ambiguous
(level is convertible to bool, and so it might could match f(bool, int)
since the int parameter has a default value). However, what I don't
understand is why it is NOT ambiguous without the const. Any insight?
-Alan