std :: typeid :: name()的奇怪输出 [英] Strange output of std::typeid::name()

查看:251
本文介绍了std :: typeid :: name()的奇怪输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 typeid 来获取std :: vector :: size_type的类型名称和零大小的类A,并使用以下代码( cppreference ):

 # include< iostream> 
#include< vector>
#include< typeinfo>

using namespace std;

class A {};

int main()
{
vector< int> v(10);

vector< int> :: size_type s = v.size();

A a;

cout<< typeid(s).name()< endl
cout<< typeid(a).name()<< endl

};

我有这个输出:

  m 
1A

之前A是空基类优化的结果,但m代表什么,这是正常吗?



我使用以下gcc版本:g ++(Ubuntu 4.4.3-4ubuntu5.1)4.4.3

c ++ filt 可读:

  $ ./test | c ++ filt -t 
unsigned long
A


I used typeid to get the type names of the std::vector::size_type and a zero sized class A with the following code (cppreference):

#include<iostream>
#include <vector>
#include <typeinfo>

using namespace std;

class A {};

int main()
{
    vector<int> v(10); 

    vector<int>::size_type s = v.size(); 

    A a; 

    cout << typeid(s).name() << endl;
    cout << typeid(a).name() << endl;

};

And I got this as output:

m
1A

I guess that "1" before "A" is a result of the Empty Base Class Optimization, but what does "m" stand for and is this normal?

I am using the following gcc version: g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3

解决方案

G++ uses implementation-defined naming for the types, but it also offers the utility c++filt to make them human-readable:

$ ./test | c++filt -t
unsigned long
A

这篇关于std :: typeid :: name()的奇怪输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆