typeid运算符的奇怪行为? [英] Strange behaviour of the typeid operator?
本文介绍了typeid运算符的奇怪行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用XCode 3.2.3(64位),我得到以下奇怪的输出。我做错了什么?
Using XCode 3.2.3 (64-bit), I get following strange output. What am I doing wrong?
#include <iostream>
#include <typeinfo>
struct student {
};
int main()
{
int i;
student obj;
std::cout << typeid(i).name() << "\n";
std::cout << typeid(obj).name() << "\n";
return 0;
}
输出:
i
7student
推荐答案
发生了什么没有什么特别的。只是 typeid
不答应返回类型的原始名称,而只是 a 名称。
What's going on is nothing special. Just that typeid
doesn't promise to return the "original" name of the type, but just a name.
函数返回一个实现定义的字符串,如果你幸运的话,它是可识别的,但它不承诺。
The function returns an implementation-defined string, which, if you're lucky, is recognizable, but it makes no promise of that.
这篇关于typeid运算符的奇怪行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文