rvirtual and inline function with different prototypes (to enforce default parameter)
Suppose I have this base + derived class:
Code:
class B
{
public:
virtual void Foo( int x, int mode );
};
class C : public B
{
public:
virtual void Foo( int x, int mode );
};
Now I can do
Code:
C* bla;
bla->Foo(1,0);
Similar to the C class, I have a few hunderd other classes derived from B as well.
Now, I want to have a default value for the 'mode' parameter. But if I do this:
Code:
class B
{
public:
virtual void Foo( int x, int mode=0 );
};
And change the function call into:I get an error "C::Foo requires 2 parameters".
Ok, so I thought I could work around this by adding an inline wrapper function to the base class, which calls the actual function, like this:
Code:
class B
{
public:
virtual void Foo( int x, int mode );
inline void Foo( int x ) { Foo(x,0); }
};
But now, when calling bla->Foo(1) my compiler still says that C::Foo requires 2 parameters. While I obviously mean the new inlined B::Foo here.
Why is this? Is it somehow invalid or ambiguous what I'm doing here?
(PS. Workarounds: add the =0 default in all derived classes as well (lotsa work), or keep the above inline function and change the function calls into bla->B::Foo(1) or ((B*)bla)->Foo(1) (somewhat less work in my case), but I'm just wondering)