をしない私は、GCC 出力にC++コンパイラ、TYPE_INFO上のコード::名前実行しています:C++ filtのデマングルのtypeid名
#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
は、私が以前と同じ出力を得ます。他の解決策?あなたは、次の動作するはずですので、タイプのためc++filt -t
を使用する必要が
[名前のマングリング](http://refspecs.linux-foundation.org/cxxabi-1.83.html#mangling)は種類が複雑ではなく、確かにそうではありません...私はあなたの質問に対する答えはありますが、回避策は自分でタイプを読むことです。 'P'' 6Circle'サークルオブジェクトへのポインタ(6は名前の長さです)' P'は '8triangle'三角形(8文字)へのポインタです。 –
ええと、それは簡単です。ありがとうございます。同じものを入手するためのよりクリーンな方法があるかどうかを知りたいだけでした。 –