C++ typeid输出信息格式
用这段程序做演示:
#include <iostream>
#include <typeinfo>class Base { virtual void dummy() {} };
class Derived : public Base { /* ... */ };int main() {Base* base_ptr = new Derived;// Using typeid to get the type of the objectstd::cout << "Type: " << typeid(*base_ptr).name() << '\n';std::cout << "Type: " << typeid(base_ptr).name() << '\n';delete base_ptr;return 0;
}
输出为:
Type: 7Derived
Type: P4Base
这里的数字应该是表示类型名的长度。