So I'm playing around with the visitor pattern for the first time, and wonder why I have to write the accept function multiple times for each derived class.
class object
{
public:
void accept(visitor *v) { v->visit(this); }
....
class derived : object
{
public:
void accept(visitor *v) {.... // redundancy in my eyes!!
Do I really have to define that accept function for every single visitable? Is there a way to just write it once in the base class and have this refer to the particular derived class pointer without having to cast?
Thanks
Aucun commentaire:
Enregistrer un commentaire