Instead of doing the following everytime
start(); // some code here stop();
I would like to define some sort of macro which makes it possible to write like:
startstop() { //code here }
Is it possible in C++?
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 do something very close using a small C++ helper class.
Then in your code:
When execution enters the block and constructs the
ssvariable, thestart()function will be called. When execution leaves the block, theStartStopperdestructor will be automatically called and will then callstop().