Identify two functions

I would like to create something for use in Visual Studio (C ++), perhaps an extension that will be used with two well-known functions inside. Let me try to explain. Let's say I have two functions start () and stop () . I usually use the following functions:

start(); do something... stop(); 

In some cases, it may be confusing to know what starts and what stops:

 start(); do something... start(); do something... start(); do something... stop(); stop(); stop(); 

To understand what starts and what stops, I need to identify all the lines manually. I would like to create something like:

 start(){ do something.... start(){ do something ... } } 

Each time I close the start brackets, the stop function will be closed and the code will be much more organized.

Do you have any idea on how to do this or something like that?

+7
c ++ visual-studio
source share
2 answers

In C ++ 11, you can use such code, but you need to understand the high-order functions and C ++ lambdas.

 #include <iostream> class Executor { public: void perform(void (*routine)()) { start(); routine(); stop(); } void start() { std::cout << "start" << std::endl; } void stop() { std::cout << "stop" << std::endl; } }; int main() { Executor executor; executor.perform([](){ std::cout << "perform 0" << std::endl; }); executor.perform([](){ std::cout << "perform 1" << std::endl; Executor executor; executor.perform([](){ std::cout << "perform 10" << std::endl; }); }); } 
+4
source share

You can also do something like this.

  start(); { //do something... start(); { //do something... start(); { //do something... } stop(); } stop(); } stop(); 

this will help you determine what start(); refers to start(); stop(); statement // do something .

+3
source share

All Articles