KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How would I catch a member variable by value when using C++11 lambda expressions? Using the [my_member] syntax doesn't seem to work, and implicit capture uses the this pointer. What is need is a way to explicitly specify capture type of member variables. Is that possible? My workaround for now is: void member_function() { std::shared_ptr<my_member_class> my_member_copy = my_member; // this shouldn't be necessary std::async([=]{ std::cout << *my_member_copy; }); // std::async([=]{ std::cout << *my_member_; }); // wrong, my member could be potentially out of scope }
Tags (comma-separated)
Save Edits
Cancel