c++ - Using Templates to resolve virtual methods -
this issue involves using templates resolve virtual members in dispatch pattern. note: not same virtual template method questions asked on stackoverflow . * edit 1: corrected syntax errors, added clarifications. given following: #include <string> #include <iostream> class field_interface { public: virtual std::string get_field_name(void) const = 0; }; class field_integer : public field_interface { public: std::string get_field_name(void) const { return "int";} }; class field_string : public field_interface { public: std::string get_field_name(void) const { return "varchar";} }; class field_double : public field_interface { public: std::string get_field_name(void) const { return "double";} }; class abstract_visitor { public: virtual void visit(const field_integer& fi) = 0; virtual void visit(const field_string& fi) = 0; virtual void visit(const field_double& fi) = 0; ...