2013-04-28 56 views
4

我检查某些类型的变量,并得到了一些混乱的结果:理解的typeid的输出()名称()

#include <iostream> 
#include <typeinfo> 
using namespace std; 

int main(void) { 
    int number = 5; 
    int* pointer = &number; 

    cout << typeid(number).name() << endl;  // i 
    cout << typeid(pointer).name() << endl;  // Pi 
    cout << typeid(&pointer).name() << endl; // PPi 

    return 0; 
} 

i意味着int,但什么PiPPi是什么意思? Pointer int

+1

他们没有任何意义。我怀疑你正在使用GCC,它使用该系统为'typeid'命名类型。如果你看到像MSVC这样的东西,它们会有所不同。 – chris 2013-04-28 21:27:51

+1

http://mentorembedded.github.io/cxx-abi/abi.html并假设您使用的是gcc:http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html – 2013-04-28 21:34:08

回答

5

它分别表示指向一个整数的指针和指向一个整数的指针。

-6

双斜线后面的内容是评论。

例如

int main() { 
    int i = 0; // This is a comment. 
    // This is also a comment. 
    // i 
    // The above line is a comment. 
    // PPi 
    // The above line is ALSO a comment. 
    return 0; 
} 

希望澄清一下。也就是说,编写该代码的人必须表示我指的是整数,Pi指向一个整数的指针,而PPi指的是指向指向一个整数的指针。

+2

-1大多数“答案”不是真正的答案。 OP显然使用注释来指示'cout'语句的输出。 – 2013-04-28 21:34:49

4
  • 我:整数
  • 皮:指向整数变量
  • PPI:指针指向整数的标准C++方面的变量