views:

38

answers:

1

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

+4  A: 

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).

Mike Seymour
This worked. I didn't know about this use of the keyword using. Thank you.
Paul