相关疑难解决方法(0)

353
推荐指数
18
解决办法
30万
查看次数

为什么typeid.name()使用GCC返回奇怪的字符以及如何使其打印未拼写的名称?

我怎么运行这个main.cpp:

#include <iostream>
#include <typeinfo>

using namespace std;

struct Blah {};

int main() {
  cout << typeid(Blah).name() << endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

通过使用GCC 4.4.4版进行编译:

g++ main.cpp
Run Code Online (Sandbox Code Playgroud)

我明白了:

4Blah
Run Code Online (Sandbox Code Playgroud)

在Visual C++ 2008上,我会得到:

struct Blah
Run Code Online (Sandbox Code Playgroud)

有没有办法让它只是打印Blahstruct Blah

c++ gcc g++ rtti

43
推荐指数
5
解决办法
3万
查看次数

标签 统计

c++ ×2

c++11 ×1

g++ ×1

gcc ×1

rtti ×1

typeof ×1

variables ×1