Creating a new scope with a C++ Macro?
Is this even possible? I would like to write a macro that makes it easier
to use some of my classes functionality.
Lets say I have 2 member functions in my class, startScope() and
endScope(), where startScope() sets up parameters for some operation that
needs to be executed in its own scope, and endScope() preforms cleanup
(similar to a constructor and destructor concept).
Currently, I do this:
myClassInstance.startScope(); //call the start function
{ //start scope
//CREATE LOCAL VARS
//DO STUFF IN THIS SCOPE
myClassInstance.endScope(); //cleanup
} //end scope, destroy locals
But would like to do something like this instead:
NEWSCOPE(myClassInstance) //calls startScope()
{
//CREATE LOCAL VARS
//DO STUFF IN THIS SCOPE
} // calls endScope() and destroys locals
My thought was to write a macro class that can be instantiated when the
macro is used and startScope() and endScope() could be implemented in the
constructor/destructor... or something like that...
Is this the right way to think about this or is there another way to write
a macro that can essentially wrap around code written by the user?
No comments:
Post a Comment