How can I compile C ++ 11 code with Orwell Dev-C ++?

Trying to compile the following code:

#include <iostream> #include <memory> struct Foo { Foo() { std::cout << "Foo::Foo\n"; } ~Foo() { std::cout << "Foo::~Foo\n"; } void bar() { std::cout << "Foo::bar\n"; } }; void f(const Foo &foo) { std::cout << "f(const Foo&)\n"; } int main() { std::unique_ptr<Foo> p1(new Foo); // p1 owns Foo if (p1) p1->bar(); { std::unique_ptr<Foo> p2(std::move(p1)); // now p2 owns Foo f(*p2); p1 = std::move(p2); // ownership returns to p1 std::cout << "destroying p2...\n"; } if (p1) p1->bar(); // Foo instance is destroyed when p1 goes out of scope } 

with Orwell Dev-C ++ 5.3.0.3 throws the following error:

'unique_ptr' is not a member of 'std'.

How can I handle this?

+3
source share
1 answer

Please ensure that you compile the correct -std flag. The default value that Orwell Dev-C ++ uses (does not skip any -std option) will not allow some brilliant new C ++ 11 features, such as unique_ptr, to be used. The fix is ​​pretty simple:

  • To compile without a project, follow the link: Tools → Compiler Options → (select your compiler) → Settings → Code Generation → (set the “Language Standard” to C ++ 11)
  • To compile the project, go to: Project → Compiler → Code Generation → (set the “Language Standard” to C ++ 11)

Here is a bit more information about the -std sign: http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

As you can see, GCC uses the GNU C ++ 03 dialogs by default (which does not seem to support unique_ptr).

+10
source

Source: https://habr.com/ru/post/1482697/


All Articles