Suppose I have this base + derived class:Now I can doCode:class B { public: virtual void Foo( int x, int mode ); }; class C : public B { public: virtual void Foo( int x, int mode ); };Similar to the C class, I have a few hunderd other classes derived from B as well.Code:C* bla; bla->Foo(1,0);
Now, I want to have a default value for the 'mode' parameter. But if I do this:And change the function call into:Code:class B { public: virtual void Foo( int x, int mode=0 ); };I get an error "C::Foo requires 2 parameters".Code:bla->Foo(1);
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:
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.Code:class B { public: virtual void Foo( int x, int mode ); inline void Foo( int x ) { Foo(x,0); } };
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)



LinkBack URL
About LinkBacks



