I want to implement the Visitor pattern in C++ like this:
class Visitor{
public:
virtual ~Visitor();
virtual void visit(C & t)=0;
};
class V : public Visitor{
public:
void visit(C &c);
};
class C{
public:
void accept(Visitor &v){ v.visit(*this); }
};
But the compiler complains abount 2 syntax errors:
Unknown identifier C and Visitor.
Where is the problem?
At the moment the compiler sees
name
Cis unknown.You need to forward-declare
class CbeforeVisitor