samedi 2 mai 2015

I can't make C++11 features work in g++ 4.9, either in Cygwin or in Ubuntu

I see that several people have asked related questions, but I still don't get it. I am trying to run a sample C++11 program. It behaves the same under Cygwin and Ubuntu. Exactly as shown below.

I have tried -std=c11 and -std=c0x. According to what I read, the 4.8 and up version of g++ handles the new syntax. And yet, this is my result. What's happening?

rhedin@RHEDIN1-T430 /cygdrive/c/work/150502
$ cat lamb.cpp
#include <iostream>

using namespace std;

int main()
{
    auto func = [] () { cout << "Hello world"; };
    func(); // now call the function
}

rhedin@RHEDIN1-T430 /cygdrive/c/work/150502
$ g++ lamb.cpp -o lamb
lamb.cpp: In function ‘int main()’:
lamb.cpp:7:10: error: ‘func’ does not name a type
     auto func = [] () { cout << "Hello world"; };
          ^
lamb.cpp:8:10: error: ‘func’ was not declared in this scope
     func(); // now call the function
          ^

rhedin@RHEDIN1-T430 /cygdrive/c/work/150502
$ g++ --version
g++ (GCC) 4.9.2
Copyright (C) 2014 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.


rhedin@RHEDIN1-T430 /cygdrive/c/work/150502
$

Aucun commentaire:

Enregistrer un commentaire