In C++, I need to defined a macro. That macro would take as parameter a \"block\" of code.
Can we safely use several lines of code as parameter of a macro fu
The main problem that I see is that expr
isn't an expression at all. It even contains a declaration. Obviously, you're going to have a problem with two variables k
defined in my_function
.
If you can use C++0x (e.g. VS2010, GCC4.6) then you can use lambda's to capture context. Not that you'd need to capture context for such a simple case, nor do you need templates, your macro just needs a std::function
.