[英]Why does g++ (4.8.2) use c++0x as default?
自c ++ 11起,我有一个使用std :: unique_ptr支持的代码。
#include <memory>
int main() {
std::unique_ptr<int> p_int(new int(3));
return 0;
}
我可以构建此代码,但仍然感到困惑。 因为我的g ++的版本是4.8.2,它支持c ++ 11。 g ++默认使用c ++ 0x的原因是什么? 我应该如何将c ++ 11设置为默认值? 现在我正在使用cmake,所以也许我应该在CMakeLists.txt中设置c ++ 11。
$ which g++
/usr/bin/g++
$ g++ --version
g++ (20140812 (SCEL u2.0.0.0)) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ main.cc
main.cc: In function ‘int main()’:
main.cc:4:2: error: ‘unique_ptr’ is not a member of ‘std’
std::unique_ptr<int> p_int(new int(3));
^
main.cc:4:18: error: expected primary-expression before ‘int’
std::unique_ptr<int> p_int(new int(3));
^
main.cc:4:18: error: expected ‘;’ before ‘int’
$ g++ main.cc -std=c++11 // this is ok
Althoguh我的问题对它的构建不是那么关键,我想清除我的想法! 任何帮助将不胜感激。 谢谢!
“ g ++使用c ++ 0x作为默认值的原因是什么 : 否 。 c++0x
是c++11
工作草案的名称
g ++默认使用-std=gnu++98
。 这是带有GNU扩展的c ++ 98。 由于长期以来一直是默认设置,因此在可预见的将来很可能仍将使用默认设置,以避免破坏与其一起构建的代码。
如果要使用c++11
作为默认值,则可以在bash中创建一个别名,例如:
alias g++="g++ -std=c++11"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.