C ++ filter does not expand type name

I run the code in the GCC C ++ compiler to output the folder_name: 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'; } 

but I get the following results:

 P6Circle P8triangle 

and when dismantling,

 ./shape | c++filt 

I get the same result as before. Any other solution?

+6
source share
2 answers

You need to use c++filt -t for types so that the following works:

 ./shape | c++filt -t 

the man page for a C ++ filter says the following for -t :

An attempt to mark up types as well as function names. This is disabled by default, since malformed types are usually used only inside the compiler, and they can be confused with undamaged names. For example, a function called "a", processed as a garbled type name, will be decoupled from the "signed char".

+10
source

What version of GCC (and its corresponding libstdc ++) are you using?

With GCC 4.8, I have

 static inline std::string demangled_type_info_name(const std::type_info&ti) { int status = 0; return abi::__cxa_demangle(ti.name(),0,0,&status); } 

and then i can use

 std::cout << demangled_type_info_name(typeid(*ptr)) << std::endl; 

where ptr points to some object with RTTI (i.e. with some virtual methods, especially with a virtual destructor).

+1
source

Source: https://habr.com/ru/post/954600/