Run Time Type Information

Q.

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    #include 
4.
    using namespace std;
5.
    class base 
6.
    { 
7.
        virtual void f(){} 
8.
    };
9.
    class derived : public base {};
10.
    int main () 
11.
    {
12.
        try 
13.
        {
14.
            base* a = new base;
15.
            base* b = new derived;
16.
            cout << typeid(*a).name() << 't';
17.
            cout << typeid(*b).name();
18.
        } 
19.
        catch (exception& e) 
20.
        { 
21.
            cout << "Exception: " << e.what() << endl; 
22.
        }
23.
        return 0;
24.
    }
A. base*
B. derived*
C. 4base and 7derived
D. None of the mentioned

Answer : Option C

Explanation :

In this program, We apply the typeid to the polymorphic class.
Output:
$ g++ rtti2.cpp
$ a.out
4base 7derived