我有一个功能
void fun(int j, int i = 10);
我想通过宏函数来调用乐趣。
#define fun1(x) fun(10)
#define fun1(x, y) fun(x, y)
我怎样才能做到这一点?
我有一个功能
void fun(int j, int i = 10);
我想通过宏函数来调用乐趣。
#define fun1(x) fun(10)
#define fun1(x, y) fun(x, y)
我怎样才能做到这一点?
为什么要在这里使用宏?在 C++ 中,使用内联函数会更容易也更惯用。
一般来说,如果你陈述你的问题,而不仅仅是想象的解决方案,你可能会得到更好的帮助。
您不能像函数一样根据参数的数量重载宏。
你最好只调用这个函数。
一些预处理器很有趣尝试:
#define fun1 fun
或者
#define fun1(...) fun( __VA_ARGS__)
或者
#define fun1(x...) fun(x)