相关疑难解决方法(0)

C++中的'typeid'与'typeof'

我想知道有什么区别之间typeid以及typeof在C++中.这就是我所知道的:

此外,这里是我创建的测试代码测试,我发现typeid它不会返回我的预期.为什么?

main.cpp中

#include <iostream>  
#include <typeinfo>  //for 'typeid' to work  

class Person {  
    public:
    // ... Person members ...  
    virtual ~Person() {}  
};  

class Employee : public Person {  
    // ... Employee members ...  
};  

int main () {  
    Person person;  
    Employee employee;  
    Person *ptr = &employee;  
    int t = 3;  

    std::cout << typeid(t).name() << std::endl;  
    std::cout << typeid(person).name() << std::endl;   // …
Run Code Online (Sandbox Code Playgroud)

c++ typeof typeid

144
推荐指数
5
解决办法
32万
查看次数

标签 统计

c++ ×1

typeid ×1

typeof ×1