I have got a scenario where it appears such as the compiler is not locating the base class definition/implementation of the virtual function with similar title as the second member function.
struct One struct Two struct Base amplifier ) virtual void func( Two &lifier ) = struct Derived : public Base amplifier ) void Base::func( One &lifier ) void Derived::func( Two &lifier ) // elsewhere void this_fails_to_compile()
I am using Visual C++ 2008. The mistake message is:
error C2664: 'Derived::func' : cannot convert parameter 1 from 'One' to 'Two &'
I'd have believed that the kind based dispatch works and call the defined base class function. Basically give a
Derived::func( One &lifier ) it will compile and obtain known as properly, however in my situation, that version from the function could be completed in the bottom class in most cases derived classes don't have to implement it themselves. I am presently working around it by placing a in a different way named, non-virtual function within the base class that forwards the phone call to work leading to the issue:
// not virtual, although I do not believe that matters void Base::work_around( One &lifier one )
That actually works but is clearly under ideal.
What inheritance and/or title-hiding rule am I missing here?
You're hiding the technique within the derived class. The easiest option would be to include a using declaration towards the derived class.
struct Derived : public Base amplifier )
The problem is the fact that once the compiler attempts to research the
func identifier within the call
d.func(one) it needs to do this from
Derived upwards, however it stop within the first context where it finds the
func identifier, which within this situation it's
Derived::func. No further research is carried out and also the compiler was seeing just the
Derived::func( Two&lifier ).
With the addition of the
using Base::func directive, once the compiler sees the
Derived definition it brings all
Base::func terms into scope, and it'll discover that there's a
Base::func( One &lifier ) which was not overridden in
Note additionally that should you be calling via a mention of the
Base, then your compiler would find both overloads of
func and would dispatch properly each one of these towards the final overrider.
Derived d Base &lifier b = d b.func( one ) // ok without 'using Base::func' directive
func(One&lifier) function in
Derived. You could utilize properly accredited title:
d.Base::func( one )