-
What is the output of this program?
#include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class BaseClass
{
virtual void f(){}
};
class DerivedClass : public BaseClass {};
int main ()
{
try
{
BaseClass* ptr1 = new BaseClass;
BaseClass* ptr2 = new DerivedClass;
cout << typeid(*ptr1).name() << " ";
cout << typeid(*ptr2).name();
}
catch (exception& excep)
{
cout << "Exception: " << excep.what() << endl;
}
return 0;
}
-
- 9BaseClass
- 12DerivedClass
- 9 12
- Both 9BaseClass and 12DerivedClass
- None of these
Correct Option: D
In this program, We apply the typeid to the polymorphic class.