New to VS 2012 and Lambada programming
I am new to VC++ 2012 and Lambada programming. I want use a local initialized varaible withint he Lambada code block.
Code:
int _tmain(int argc, _TCHAR* argv[])
{
uri_builder uri(L"http://*:2001/");
http_listener listener(uri.to_uri());
utility::string_t strPost = L"";
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
listener.support(methods::POST,[](http_request req)
{
std::cout << "Serving POST" << std::endl;
req.extract_string(true).then([req](utility::string_t body)
{
std::wcout << body << std::endl;
strPost = body;
});
});
}
In this section the compiler throws this error
Code:
Error 3 error C3493: 'strPost' cannot be implicitly captured because no default capture mode has been specified
How can I overcome this problem, how can I use it across the whole function?
Re: New to VS 2012 and Lambada programming
Ah yes, lambada programming.
Where you kill bugs with your awesome sexy dance moves. :-)
1) it's lambda (from the greek letter 'lambda')
better get this right before people make fun of you.
oh dear too late ;-)
2)
you're using strPost, but you have not mentioned strPost in the capture clause, nor have you specified a default capture mode (by value or by reference) for variables.
so you get an error.
since you're changing it, you probably want to capture by reference . IN that case add &strPost to the capture clauses (or add & to capture anything other than req by reference).
Re: New to VS 2012 and Lambada programming
Quote:
Originally Posted by
OReubens
Ah yes, lambada programming.
Where you kill bugs with your awesome sexy dance moves. :-)
1) it's lambda (from the greek letter 'lambda')
better get this right before people make fun of you.
oh dear too late ;-)
2)
you're using strPost, but you have not mentioned strPost in the capture clause, nor have you specified a default capture mode (by value or by reference) for variables.
so you get an error.
since you're changing it, you probably want to capture by reference . IN that case add &strPost to the capture clauses (or add & to capture anything other than req by reference).
Sorry, if I didn't explain well in the original post. I want a local variable to be access across various lambda code blocks.
Re: New to VS 2012 and Lambada programming
Let’s Write a “Hello Lambda!”
It's intentionally made enough stupid, in order to explain lambdas at beginners level. :)
Re: New to VS 2012 and Lambada programming
Quote:
Originally Posted by
maverick786us
[...] I want a local variable to be access across various lambda code blocks.
Beware! In your case the lambda call is asynchronous, so it's not OK to capture local variables by reference.