#include #include using namespace std; /* DERIVED must be publicly derived from class base and must have a member function named implementation. Class DERIVED can have only at most one class base among its ancestors. interface can be called only when the base object is part of a DERIVED object. */ template class base { public: void interface() const { static_cast(this)->implementation(); } }; class derived1: public base { public: void implementation() const {cout << "derived1\n";} }; class derived2: public base { public: void implementation() const {cout << "derived2\n";} }; int main() { derived1 d1; d1.interface(); derived2 d2; d2.interface(); cout << "sizeof (base) == " << sizeof (base) << "\n" << "sizeof (base) == " << sizeof (base) << "\n" << "sizeof (derived1) == " << sizeof (derived1) << "\n" << "sizeof (derived2) == " << sizeof (derived2) << "\n"; return EXIT_SUCCESS; }