C++ typeid输出信息格式
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 object
std::cout << "Type: " << typeid(*base_ptr).name() << '\n';
std::cout << "Type: " << typeid(base_ptr).name() << '\n';
delete base_ptr;
return 0;
}
输出为:
Type: 7Derived
Type: P4Base
这里的数字应该是表示类型名的长度。

浙公网安备 33010602011771号