c ++ filt不会取消typeid名称的修饰 [英] c++filt does not demangle typeid name

查看:197
本文介绍了c ++ filt不会取消typeid名称的修饰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在GCC C ++ 编译器上运行代码,以输出type_info :: name:

I am running a code on GCC C++ compiler, to output the type_info::name:

#include <iostream>
#include <typeinfo>

using namespace std;

class shape {
   protected:
   int color;
   public:
   virtual void draw() = 0;
   };


class Circle: public shape {
   protected:
   int color;
   public:
   Circle(int a = 0): color(a) {};
   void draw();
   };

   void Circle::draw() {
   cout<<"color: "<<color<<'\n';
   }

class triangle: public shape {
   protected:
   int color;
   public:
   triangle(int a = 0): color(a) {};
   void draw();
   };

   void triangle::draw() {
   cout<<"color: "<<color<<'\n';
   }

int main() {
   Circle* a;
   triangle* b;
   cout<<typeid(a).name()<<'\n';
   cout<<typeid(b).name()<<'\n';
   }

但是我得到以下结果:

P6Circle
P8triangle

并在拆箱时

./shape | c++filt  

我得到与之前相同的输出.还有其他解决方案吗?

I get the same output as earlier. Any other solution?

推荐答案

您需要对类型使用c++filt -t,这样才能正常工作:

You need to use c++filt -t for types so the following should work:

./shape | c++filt -t

c ++ filt的手册页-t表示以下内容:

the man page for c++filt says the following for -t:

尝试对类型和函数名称进行解密.默认情况下,此选项是禁用的,因为错误类型通常仅在编译器内部使用,并且它们可能与非错误名称混为一谈.例如,将一个称为"a"的函数视为类型错误的名称,将其分解为"signed char".

Attempt to demangle types as well as function names. This is disabled by default since mangled types are normally only used internally in the compiler, and they can be confused with non-mangled names. For example, a function called "a" treated as a mangled type name would be demangled to "signed char".

这篇关于c ++ filt不会取消typeid名称的修饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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