jeudi 10 décembre 2020

How can I implement the visitor patter with return type in C++

I want to implement the visitor pattern for one of my class without having to depend on the types that will implement the interface to visit them.

My solution was this:

class model::VisitableNode {
public:
   template<class T>
   virtual T accept(NodeVisitor<T>);
}

But C++ says that it doesn't support template + virtual methods

Node in my application will have only one implementation but if I don't use a template return type my model class will depend on the toolkit that I'm using to create the graphic for my app.

Aucun commentaire:

Enregistrer un commentaire