![typeid详解](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
| |
| |
| |
| |
#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
{
}
![typeid详解](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
![typeid详解](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
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<<