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?
P
pointer to6Circle
Circle object (the 6 is the length of the name)...P
pointer to8triangle
triangle (8 characters). – Telesthesia