Strange type operator behavior?

Using Xcode 3.2.3 (64-bit), I get the following weird output. What am I doing wrong?

#include <iostream>
#include <typeinfo>

struct student {

};

int main()  
{  
    int i;
    student obj;

    std::cout << typeid(i).name() << "\n";
    std::cout << typeid(obj).name() << "\n";

    return 0;
}

Conclusion:

i  
7student
+3
source share
2 answers

What happens is nothing special. It just typeiddoes not promise to return the "original" type name, but just a name.

The function returns a string defined by the implementation, which, if you're lucky, is recognizable, but it does not promise this.

+4
source

name() type_info . , -, , . , ++ ISO (18.5.1.7) , " NTBS" ( ). , "neener neerer, ". Java Class<?>, , .

+7

Source: https://habr.com/ru/post/1784437/


All Articles