
Hi. I start learning boost.Here is very simple code I can't compile. typedef std::vector<LPCWSTR> type; type test; test[0] = (_T("1")); test[1] = (_T("2")); test[2] = (_T("3")); std::for_each(test.begin(),test.end(), OutputDebugString(_1)); Got compilation error : ----------------------------------------------------------- error C2664: 'OutputDebugStringW' : cannot convert parameter 1 from 'boost::lambda:laceholder1_type' to 'LPCWSTR' ----------------------------------------------------------- Can anybody point me at mistakes I made in the code?

Yurij Zhacun wrote:
Hi. I start learning boost.Here is very simple code I can't compile.
typedef std::vector<LPCWSTR> type; type test; test[0] = (_T("1")); test[1] = (_T("2")); test[2] = (_T("3"));
std::for_each(test.begin(),test.end(), OutputDebugString(_1));
Got compilation error : ----------------------------------------------------------- error C2664: 'OutputDebugStringW' : cannot convert parameter 1 from 'boost::lambda:laceholder1_type' to 'LPCWSTR' -----------------------------------------------------------
Can anybody point me at mistakes I made in the code?
Since OutputDebugStringW (which is a result of OutputDebugString macro expansion) is a mere function, the expression OutputDebugString(_1) means that you actually try to call it and pass its result to the for_each. What you need is to create a functor that would delay that call. You should try something like this: std::for_each(test.begin(),test.end(), boost::lambda::bind(&OutputDebugString, boost::lambda::_1)); or std::for_each(test.begin(),test.end(), boost::bind(&OutputDebugString, _1)); The first is Boost.Lambda, the second is Boost.Bind.

Yurij Zhacun wrote:
Hi. I start learning boost.Here is very simple code I can't compile.
typedef std::vector<LPCWSTR> type; type test; test[0] = (_T("1")); test[1] = (_T("2")); test[2] = (_T("3"));
std::for_each(test.begin(),test.end(), OutputDebugString(_1));
Got compilation error : ----------------------------------------------------------- error C2664: 'OutputDebugStringW' : cannot convert parameter 1 from 'boost::lambda:laceholder1_type' to 'LPCWSTR' -----------------------------------------------------------
Can anybody point me at mistakes I made in the code?
Oh, and BTW that will crash since you didn't do test.resize().
participants (2)
-
Andrey Semashev
-
Yurij Zhacun