g++编译器打印的类型名比较晦涩,vc编译器打印的类型名很清晰,参考这里。下面给出一个用g++打印清晰类型名的一个示例。
1、源码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <string>
#include <iostream>
#include <typeinfo>
using
namespace
std;
#include <cxxabi.h>
const
string GetClearName(
const
char
* name)
{
int
status = -1;
char
* clearName = abi::__cxa_demangle(name, NULL, NULL, &status);
const
char
*
const
demangledName = (status==0) ? clearName : name;
string ret_val(demangledName);
free
(clearName);
return
ret_val;
}
int
main()
{
int
num = 3;
cout <<
"num => "
<<
typeid
(num).name()
<<
" => "
<< GetClearName(
typeid
(num).name())
<< endl;
cout <<
"double => "
<<
typeid
(
double
).name()
<<
" => "
<< GetClearName(
typeid
(
double
).name())
<< endl;
return
0;
}
|
2、截图
***
本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1241224如需转载请自行联系原作者
RQSLT