Compiler doesn't find methods from base class
I am having a problem with my virtual methods in a derived class. Here are my (simplified) C++ classes.
class Base
virtual method accept( MyVisitor1* v ) { /*implementation is here*/ };
virtual method accept( MyVisitor2* v ) { /*implementation is here*/ };
virtual method accept( MyVisitor3* v ) { /*implementation is here*/ };
class DerivedClass
virtual method accept( MyVisitor2* v ) { /*implementation is here*/ };
The following use causes VS 2005 to give: "error C2664: 'DerivedClass::accept' : cannot convert parameter 1 from 'Visitor1*' to 'Visitor2 *'".
DerivedClass c;
开发者_运维百科MyVisitor1 v1;
c.accept(v1);
I was expecting the compiler to find and call Base::accept(MyVisitor1) for my DerivedClass as well. Obviously this is not working, but I don't understand why. Any ideas?
Thanks,
Paul
The accept
member of DerivedClass
hides any members of the base class with the same name, even if they have different signatures. To include them, add the following to the definition of DerivedClass
:
using Base::accept;
(I'm assuming that DerivedClass
does derive from Base
; your snippet doesn't explicitly say that).
精彩评论