What’s the closest thing in C++ to retroactively defining a superclass of a defined class?
You can do the following: class C { struct Interface { virtual void bar() = 0; virtual ~Interface(){} }; template <class T> struct Interfacer : Interface { T t; Interfacer(T t):t(t){} void bar() { t.bar(); } }; std::unique_ptr<Interface> interface; public: template <class T> C(const T & t): interface(new Interfacer<T>(t)){} void bar() { interface->bar(); } }; … Read more