开发者

Macros with multiple parentheses

How can I create a macro with multiple parentheses? I don't need variadic number of arguments, I just want to be able to call my macro like.

MY_MACRO(arg0, arg1)(arg2) 

...instead of:

M开发者_如何学GoY_MACRO(arg0, arg1, arg2) 

Update:

Let's say I have a macro defined like; #define MY_MACRO(a, b, c) (a*b/c) and called like MY_MACRO(1,2,3). How do I transform this macro to being called like MY_MACRO(1, 2)(3)

I.e., what I want to do is write my macro as usual, only take the last argument in it's own parenthesis.


#define MY_MACRO(a, b) a, b, MY_MACRO1
#define MY_MACRO1(c) c

Now doing

MY_MACRO(arg0, arg1)(arg2)

Will do

MY_MACRO(arg0, arg1)(arg2)
a, b, MY_MACRO1 (arg2)
arg0, arg1, MY_MACRO1 (arg2)
arg0, arg1, c
arg0, arg1, arg2


#include <iostream>
using namespace std;

#define MY_MACRO(a, b) (a * b)/ MY_MACRO1
#define MY_MACRO1(c) c

int main() {
    int n = MY_MACRO( 5,6)(3);
    cout << n << endl;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜