Thursday, 21 August 2014

typeid, polymorphic class Using C++ Programing


#include
#include
#include
using namespace std;
class CBase 
virtual void f()
{} 
};
class CDerived : public CBase {};
int main () 
{
try 
{
CBase* a = new CBase;
CBase* b = new CDerived;
cout << "a is: " << typeid(a).name() << '\n';
cout << "b is: " << typeid(b).name() << '\n';
cout << "*a is: " << typeid(*a).name() << '\n';
cout << "*b is: " << typeid(*b).name() << '\n';
catch (exception& e) 
{ cout << "Exception: " << e.what() << endl; 
}
return 0;
}

No comments:

Post a Comment