下面这段代码:
int main(void)
{
int a = 10;
typeof(a) b = a + 1;
}
在g++5.4中默认编译可通过,但是若加上c++11选项就编译出错。
这是因为typeof是GNU扩展,而不是C++标准。
最简单的解决办法是使用gnu++11,而非c++11。
g++ a.cpp -std=gnu++11
总结:
This mode can be selected with the -std=c++11 command-line flag, or -std=gnu++11 to enable GNU extensions as well.
-std=c++11,支持C++11标准;
-std=gnu++11,支持C++11标准和GNU扩展特性;