Implementing the visitor pattern using C++ Templates
This can be done in C++11 using variadic templates. Continuing from Pete’s answer: // Visitor template declaration template<typename… Types> class Visitor; // specialization for single type template<typename T> class Visitor<T> { public: virtual void visit(T & visitable) = 0; }; // specialization for multiple types template<typename T, typename… Types> class Visitor<T, Types…> : public Visitor<Types…> … Read more