我正在 GCC 上运行代码C++编译器,输出 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
我得到与之前相同的输出。还有其他解决方案吗?
你需要使用c++filt -t
对于类型,以下应该有效:
./shape | c++filt -t
the c++filt 的手册页 http://linux.die.net/man/1/c++filt说以下内容-t
:
尝试分解类型和函数名称。默认情况下禁用此功能,因为重整类型通常仅在编译器内部使用,并且它们可能与非重整名称混淆。例如,被视为重整类型名称的名为“a”的函数将被分解为“signed char”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)