我試圖運行一個alignof運算符的例子。當我用gcc編譯它(g ++ -std = C++ 11 alignof.cpp)時,我得不到任何錯誤。 但是,當我使用ICC(ICPC -std = C++ 11 alignof.cpp)我收到以下錯誤,我不知道爲什麼編譯:英特爾編譯器 - 錯誤:標識符「alignof」未定義
cenas.cpp(13): error: type name is not allowed
std::cout << "alignment of empty class: " << alignof(Empty) << '\n'
^
cenas.cpp(13): error: identifier "alignof" is undefined
std::cout << "alignment of empty class: " << alignof(Empty) << '\n'
^
cenas.cpp(14): error: type name is not allowed
<< "alignment of pointer : " << alignof(int*) << '\n'
^
cenas.cpp(14): error: expected an expression
<< "alignment of pointer : " << alignof(int*) << '\n'
^
cenas.cpp(15): error: type name is not allowed
<< "alignment of char : " << alignof(char) << '\n'
^
cenas.cpp(16): error: type name is not allowed
<< "alignment of Foo : " << alignof(Foo) << '\n' ;
我在同一個運行的代碼機器,我用模塊命令更改編譯器。 alignof運算符如何定義?
你確定它是由intel編譯器支持的嗎?擁有C++ 11開關是一回事,但如果他們從未實現它,這就解釋了你在這裏得到了什麼。 – Borgleader
嗯,一定是這樣的。謝謝! – dspereira004