2013-04-28 77 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++方面的變量