// This code demonstrates how to explicitly call a base class method // from a derived class. It also shows how to use a member initialization // list to initialize a base class. // // __func__ is standard, but __PRETTY_FUNCTION__ makes prettier output. #include using namespace std; class Base { public: // Note the lack of a default (no-argument) ctor. Base(char c) : stamp(c) { cout << __PRETTY_FUNCTION__ << '\n'; } int foo() { return 21; } Base & operator=(const Base &rhs) { cout << __PRETTY_FUNCTION__ << '\n'; stamp = rhs.stamp; return *this; } private: char stamp; }; class Derived : public Base { typedef Base super; public: Derived() : super('x') { cout << __PRETTY_FUNCTION__ << '\n'; } int foo() { return super::foo()*2; } }; int main() { Derived d, e; cout << "foo: " << d.foo() << '\n'; e = d; return 0; }