"Z4mainE2" 是什么意思?

What does "Z4mainE2" mean?

#include<iostream>
#include<typeinfo>
using namespace std;
int main(){
    class c1{
        public:
        int a ;

    };

c1 obj1;
cout<<typeid(obj1).name();  
}

我运行它在ideonetypeid.name()returnsZ4mainE2c1。很明显 c1 是 class 的名称,但 Z4mainE2 是什么。 为什么不只显示类型名称?

Z4mainE2"name mangling" 的结果。基本上,C++ 编译器是围绕链接器模型设计的,该模型不直接支持函数重载、运算符甚至 class 成员等内容。为了支持 C++ 的各种非 C 特性,编译器生成的目标代码将特殊序列添加到生成的名称中。虽然损坏的名称通常对程序员不可见或不重要,但某些平台上的 typeinfo 对象会直接公开它们。