Compiler doesn't find methods from base class

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-06-17T10:23:18Z Indexed on 2010/06/17 10:33 UTC
Read the original article Hit count: 296

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

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-studio