I have the following code which is seems to be lead to the infinite loop:
struct X
{
void my_func( int ) { std::cout << "Converted to int" << std::endl; }
};
struct X2 : X
{
void my_func( char value ) { my_func(value); }
};
What is the problem with it?
The second bit is infinitely recursive:
Prefix
my_funcwith the name of the base class and you will be OKEDIT Just realised that base classmy_func‘s signature is different. C++ compiler resolves the function overload statically, that means it will pick the function that best matches the type of the argument, that’s why it calls thecharoverload.For example:
Thanks Charles Bailey. The above code does not apply in this case as
X2‘smy_funchides base class’smy_func. This leaves the only solution to qualify the function with the class name.