sorry, forgot to derive ABCDerived1 form ABCBase ;) But hope you got the intention.
Hi!
The only solution I can come up with is the declaration of the visitor in your ABCBase as virtual function and visitor has a function template to dispatch different types:
class ABCVisitor
{
public:
template<class T>
void visit(T& t)
{
// no visit implemented ...
}
};
class ABCBase
{
//... dtor, copy ctor, assignment operator etc.
public:
void accept_visitor(ABCVisitor& v)
{
do_accept_visitor(v);
}
private:
virtual void accept_visitor(ABCVisitor& v)=0;
};
class ABCDerived1 : public ABCBase
{
//... dtor, copy ctor, assignment operator etc.
void accept_visitor(ABCVisitor& v)
{
v.visit(*this);
}
};
template<>
void ABCVisitor::visit<ABCDerived1>(ABCDerived1& derived)
{
// handle derived here...
}
Hope that helps,
Ovanes