jeudi 4 juin 2015

Why does g++ (4.8.2) use c++0x as default?

I have a code which uses std::unique_ptr supported since c++11.

#include <memory>

int main() {
        std::unique_ptr<int> p_int(new int(3));
        return 0;
}

I could build this code, but I'm still confused. Becuase my g++'s version is 4.8.2 which supports c++11. What's the reason that g++ uses c++0x as default? And how should I set c++11 as default? Now I'm using cmake, so maybe I should set c++11 in CMakeLists.txt..

$ 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   

Althogu my question is not so critical for its building, I want to clear my thought! Any helps will be appreciated. Thank you!

Aucun commentaire:

Enregistrer un commentaire