gpt4 book ai didi

c++filt 不 demangle typeid 名称

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:24 29 4
gpt4 key购买 nike

我在 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

man page for c++filt-t 说以下内容:

Attempt to demangle types as well as function names. This is disabled by default since mangled types are normally only used internally in the compiler, and they can be confused with non-mangled names. For example, a function called "a" treated as a mangled type name would be demangled to "signed char".

关于c++filt 不 demangle typeid 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19005744/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com