这个号码和我的typeid有什么关联

What is this number associated with my typeid?

本文关键字:什么 关联 typeid 我的 号码      更新时间:2023-10-16

程序:

#include<iostream>
#include<typeinfo>
using namespace std;
class Base
{
        public:virtual void func(){}
};
class Derived1 : public Base {};
int main()
{
        Derived1 d;
        cout<<typeid(d).name()<<endl;
        return 0;
}

输出:

8Derived1

这个数字是多少8

编译器:g++-4.8.4-2ubuntu1~14.04

它是实现定义的,没有固有的含义。检查std::typeinfo::name()引用:

返回一个实现定义的以null结尾的字符串,该字符串包含类型的名称。没有给出任何保证,特别是,对于几种类型,返回的字符串可能是相同的,并且在同一程序的调用之间会发生变化。