Strange behaviour of the typeid operator?

前端 未结 2 1925
粉色の甜心
粉色の甜心 2020-12-19 21:21

Using XCode 3.2.3 (64-bit), I get following strange output. What am I doing wrong?

#include 
#include 

struct student {

};         


        
2条回答
  •  无人及你
    2020-12-19 21:57

    The name() member function of the type_info struct is implementation-specific. There's no guarantee whatsoever that it will try to return something that matches what it says in the original program. In fact, the C++ ISO standard (18.5.1.7) actually says that this function returns "an implementation-defined NTBS" (null-terminated byte string). If it wanted to, it could have this always return the string "neener neerer I won't tell you the name of this type." This contrasts with Java's Class type, which has very strict restrictions on what it can and cannot return.

    If you’d like to convert the name from std::type_info into something more human, readable, check this other question for details.

提交回复
热议问题