I've currently trouble implementing the Visitor-Pattern in a Header-Only library in C++.
Consider following class which should support being visited by a visitor (no interface for simplicity reasions):
class Acceptor
{
void accept(Visitor* v)
{
v->visit(this);
}
};
Here is the interface for the visitors:
class Visitor
{
virtual void visit(Acceptor* t) = 0;
};
In a Header-Only lib, Acceptor.hpp must include Visitor.hpp and Visitor.hpp must include Acceptor.hpp. Since both headers are protected by Include-Guards, the later one will fail. Using forward declarations won't solve the problem, too.