12.5. Putting It All Together

RTTI Implementation

The implementation of RTTI is compiler dependent, but let's look at a typical configuration. To illustrate, consider the following Base and Derived class definitions.

class Base { 
private:
   // Base members
public:
   Base() { }
   virtual void f1() { cout << "Base::f1()" << endl; }
   virtual void f2() { cout << "Base::f2()" << endl; }
   virtual void f3() { cout << "Base::f3()" << endl; }
};
class Derived : public Base {
private:
   // Derived members
public:
   Derived() { }
   void f2() { cout << "Derived::f2()" << endl; }
   virtual void f4() { cout << "Derived::f4()" << endl; }
};

Base defines three virtual functions. Derived overrides f2() and defines virtual function f4(). Suppose we declare the following objects. ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.