#include <iostream>
#include <typeinfo>
using namespace std;
class Base
{
public:
Base( int x ):_x( x )
{
}
virtual const char* what_am_i() const
{
return typeid(*this).name();
}
protected:
int _x;
};
class Derived:public Base
{
public:
Derived( int x ):Base( x )
{
}
virtual const char* what_am_i() const
{
return typeid(*this).name();
}
};
int main()
{
Base _base(0);
Derived _derived(1);
Base *_pBase = &_derived;
if ( typeid( *_pBase ) == typeid( Derived ) )
cout << _base.what_am_i() << endl;
return 0;
}