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';
}
but I get the following results:
P6Circle
P8triangle
and on demangling,
./shape | c++filt
I get the same output as earlier. Any other solution?
Which version of GCC (and its corresponding libstdc++) are you using?
With GCC 4.8, I have
and then I can use
where
ptr
points to some object with an RTTI (i.e. with some virtual methods, notably a virtual destructor).You need to use
c++filt -t
for types so the following should work:the man page for c++filt says the following for
-t
: