나는 다음과 같은 코드로 람다 함수에 컨버터블 암시 람다 만들려고 노력 해요 :암시 적으로 강화하는 람다를 변환 :: 기능
#include <boost/function.hpp>
struct Bla {
};
struct Foo {
boost::function< void(Bla&)> f;
template <typename FnType>
Foo(FnType fn) : f(fn) {}
};
#include <iostream>
int main() {
Bla bla;
Foo f([](Bla& v) -> { std::cout << " inside lambda " << std::endl; });
};
그러나, 나는 g와 함께이 오류를 받고 있어요 ++
$ g++ --version
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
$ g++ -std=c++0x test.cpp `pkg-config --cflags boost-1.46` -o xtest `pkg-config --libs boost-1.46`
test.cpp: In function ‘int main()’:
test.cpp:21: error: expected primary-expression before ‘[’ token
test.cpp:21: error: expected primary-expression before ‘]’ token
test.cpp:21: error: expected primary-expression before ‘&’ token
test.cpp:21: error: ‘v’ was not declared in this scope
test.cpp:21: error: expected unqualified-id before ‘{’ token
을
어떤 아이디어를 어떻게 얻을 수 있습니까? 아니면 내가 그것을 성취 할 수 있다면?
UPDATEg ++ 4.5
$ g++-4.5 --version
g++-4.5 (Ubuntu/Linaro 4.5.1-7ubuntu2) 4.5.1
$ g++-4.5 -std=c++0x test.cpp `pkg-config --cflags boost-1.46` -o xtest `pkg-config --libs boost-1.46`
test.cpp: In function ‘int main()’:
test.cpp:20:22: error: expected type-specifier before ‘{’ token
컴파일러는 람다를 전혀 지원합니까? 나는 GCC가 4.5 이후에서만 그것을 지원한다고 생각했다. –
왜'std :: function' 대신에'boost :: function'을 사용합니까? – UncleBens