簡単なラムダの例を実行しようとしています。lambdaを使った単純なC++ 0xプログラムのコンパイルに問題がある
// lambda.cpp
#include <functional>
//#include <tr1/functional>
int main()
{
// Assign the same lambda expression to a function object.
function<int (int, int)> f2 = [] (int x, int y) { return x + y; };
//function<int (int, int)> f2 = [] (int x, int y) { return x + y; };
}
私はこのようにそれをコンパイルしています:
$ g++ -std=c++0x -fpermissive lamdas.cpp
lambdas.cpp: In function ‘int main()’:
lambdas.cpp:10: error: expected primary-expression before ‘=’ token
lambdas.cpp:10: error: expected primary-expression before ‘[’ token
lambdas.cpp:10: error: expected primary-expression before ‘]’ token
lambdas.cpp:10: error: expected primary-expression before ‘int’
lambdas.cpp:10: error: expected primary-expression before ‘int’
lambdas.cpp:10: error: expected ‘;’ before ‘{’ token
は、どのように私はそれがエラーなしでコンパイルするのですか?
'std :: function' –
@Martinho:応答が失敗します。 –
これはどのバージョンのGNU C++ですか?私はそれを綴る正しいソースファイル名を飛んで見たことがない! – sehe