#include<typeinfo>
#include<iostream>
using namespace std;
class A
{
public:
A()
{
a = 0;
}
int a;
};
class B
{
public:
B()
{
a = 0;
b = 0;
}
int a, b;
};
int main()
{
A clsA;
B clsB;
A *pclsA = new A();
B *pclsB = new B();
cout << typeid(clsA).name() << endl;
cout << typeid(clsB).name() << endl;
cout << typeid(pclsA).name() << endl;
cout << typeid(pclsB).name() << endl;
if(typeid(clsA) == typeid(*pclsA))
{
cout << "类型相同1" << endl;
}
if(typeid(clsA) == typeid(*pclsB))
{
cout << "类型相同2" << endl;
}
if(typeid(clsB) == typeid(*pclsB))
{
cout << "类型相同3" << endl;
}
system("pause");
return 0;
}
输出结果:
1A
1B
P1A
P1B
类型相同1
类型相同3