首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个关于typeid的有关问题

2012-03-04 
一个关于typeid的问题#include iostream#include typeinfousingnamespacestdclassmyclass1{public:my

一个关于typeid的问题
#include <iostream>
#include <typeinfo>
using   namespace   std;
class   myclass1
{public:myclass1(   ){cout < < "this   is   myclass1.\n ";}
};
class   myclass2
{public:myclass2(   ){cout < < "this   is   myclass2.\n ";}
};
int   main(   )
{int   i=0,j=0;
float   f=0;
myclass1   ob1;
myclass2   ob2;
cout < < "The   type   of   i   is: " < <typeid(i).name(   ) < <endl;
cout < < "The   type   of   f   is: " < <typeid(f).name(   ) < <endl;
cout < < "The   type   of   ob1   is: " < <typeid(ob1).name(   ) < <endl;
if(typeid(i)==typeid(j))   cout < < "The   type   of   i   and   j   are   the   same.\n ";
if(typeid(ob1)!=typeid(ob2))   cout < < "ob1   and   ob2   are   of   differing   types.\n ";
cin.get();
return   0;
}

运行结果:
this   is   myclass1.
this   is   myclass2.
The   type   of   i   is:i
The   type   of   f   is:f
The   type   of   ob1   is:8myclass1       //请问,这里怎么会有个8?应该只是显示ob1的类型名吧!
The   type   of   i   and   j   are   the   same.
ob1   and   ob2   are   of   differing   types.

[解决办法]
有也正常没有也正常。C++没规定应该输出什么。
[解决办法]
不同的编译器输出也不一样哦。
vc8输出的名字比较不错。

热点排行