|
-
April 29th, 2015, 05:45 AM
#1
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?
-
April 29th, 2015, 06:55 AM
#2
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).
-
April 29th, 2015, 11:20 PM
#3
Re: New to VS 2012 and Lambada programming
 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.
-
April 30th, 2015, 12:52 AM
#4
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.
-
April 30th, 2015, 12:59 AM
#5
Re: New to VS 2012 and Lambada programming
 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.
Last edited by ovidiucucu; April 30th, 2015 at 01:03 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|