in C# we can say:
Action act = ()=> {/*stuff*/};
act += ()=> {/*another stuff*/}`
and then call act().
I wonder how to do such thing in C++ (now with lambdas it will be quite usefull and if possible not using Boost/Qt signals)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can write something like this rather easily, by filling a
std::vector<std::function<void()>>with the lambdas and invoke every function object.However, from what I know, C# also allows you to remove a handler with
-=, which isn’t as easy to accomplish in C++. You’d need to return a token from+=which can be passed to-=to remove that specific handler.