I have a little problem and I can not understand why this code does not work:
std::for_each(users.begin(), users.end(), [](Wt::WString u) { std::cout << "ilosc: " << users.size() << std::endl; userBox_->addItem(u); });
Errors I get when compiling:
GameWidget.cpp: In lambda function: GameWidget.cpp:352:30: error: 'users' is not captured GameWidget.cpp:353:4: error: 'this' was not captured for this lambda function GameWidget.cpp: In member function 'virtual void GameWidget::updateUsers()': GameWidget.cpp:354:3: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default] GameWidget.cpp:354:4: error: no matching function for call to 'for_each(std::set<Wt::WString>::iterator, std::set<Wt::WString>::iterator, GameWidget::updateUsers()::<lambda(Wt::WString)>)' GameWidget.cpp:354:4: note: candidate is: In file included from /usr/include/c++/4.7/algorithm:63:0, from GameWidget.h:11, from GameWidget.cpp:9: /usr/include/c++/4.7/bits/stl_algo.h:4436:5: note: template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct) GameWidget.cpp:354:4: error: template argument for 'template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)' uses local type 'GameWidget::updateUsers()::<lambda(Wt::WString)>' GameWidget.cpp:354:4: error: trying to instantiate 'template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)'
I am using gcc 4.7.3 , so maybe C ++ 11 support is available for my compiler.
userBox_ is a collection, and BOOST_FOREACH working correctly for this code:
BOOST_FOREACH(Wt::WString i, users) { std::cout << "ilosc: " << users.size() << std::endl; userBox_->addItem(i); }
Thanks for any answer, I'm so curious why this is.
gadon source share