Macro function with several lines for the parameter?

后端 未结 6 997
悲哀的现实
悲哀的现实 2021-01-07 23:09

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

6条回答
  •  感情败类
    2021-01-07 23:51

    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.

提交回复
热议问题