#include <typeinfo>
#include <string>
#include <iostream>
using namespace std;
class A
{
public:
void print()
{}
};
class AA:public A
{
};
class B
{
public:
virtual void print()
{}
};
class BB:public B
{
};
int main()
{
A *a=new AA;
B *b=new BB;
cout<<typeid(a).name()<<endl;
cout<<typeid(b).name()<<endl;
cout<<typeid(*a).name()<<endl;
cout<<typeid(*b).name()<<endl;
return 1;
}
输出
class A*
class B*
class A----注意这个,有虚拟函数和没有虚拟函数的差别
class BB