
|
|
|
|
|
|
|
|
#include <iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Base b,
*pb;
pb =
NULL;
Derived
d;
cout << typeid(int).name() << endl
<< typeid(unsigned).name() << endl
<< typeid(long).name() << endl
<< typeid(unsigned long).name() << endl
<< typeid(char).name() << endl
<< typeid(unsigned char).name() << endl
<< typeid(float).name() << endl
<< typeid(double).name() << endl
<< typeid(string).name() << endl
<< typeid(Base).name() << endl
<<
typeid(b).name()<<endl
<<
typeid(pb).name()<<endl
<< typeid(Derived).name()
<< endl
<<
typeid(d).name()<<endl
<< typeid(type_info).name() << endl;
return 0;
}
using
class
class
int
{
}


Base *pb2 = dynamic_cast<Base *>(new Derived);
Base &b2 = d;
Base *pb3 = &d;
cout << typeid(pb2).name() <<endl//输出Base
*
<<
typeid(b2).name()<<endl
//输出Base
<<
typeid(pb3).name()<<endl//输出Base
*
<<
typeid(*pb3).name()<<endl;//输出Base
Base &b2 = d;
Base *pb3 = &d;
cout
class Base {virtual void f(){}; };
cout << typeid(pb2).name() <<endl//输出Base
*
<<
typeid(b2).name()<<endl
//输出Derived
<<
typeid(pb3).name()<<endl//输出Base
*
<<
typeid(*pb3).name()<<endl;//输出Derived
cout
//采用V8环境
cout<< typeid(7.84) <<endl
<< typeid(Base*) <<endl
<< typeid(&pb3) <<endl;
cout<<