I'm implementing an acyclical visitor in my project and having some difficulties with the requisite dynamic_cast. The setup looks something like this:
class Visitor;
class Entity
{
public:
virtual void accept(Visitor &v) const = 0;
};
class MyClass ;
class MyClassVisitor
{
public:
virtual void visit(const MyClass &obj) = 0;
};
class MyClass : public Entity
{
public:
virtual void accept(Visitor &v) const
{
MyClassVisitor *rcvr = dynamic_cast<MyClassVisitor*>(&v);
if(rcvr)
rcvr->visit(*this);
}
};
class SpecificVisitor : public Visitor, public MyClassVisitor
{
public:
virtual void visit(const MyClass &obj)
{
//...
}
}
However, this doesn't compile, and I'm having trouble figuring out why. With Visual Studio 2008 I get "Error C681: 'Visitor *' : invalid expression type for dynamic_cast". From what I understand, this sort of cross casting SHOULD work with dynamic cast, but the compiler is choking on it.
I've done searches on google, but I haven't been able to turn anything up. Anybody have any ideas?