这听起来可能令人困惑,但是如何在一个参数中传递多个参数呢?
#define CALL(v, look, param, expect) v(param){look(expect);}使用时的示例(不起作用):
void CALL(InitD3D, engine->InitD3D, (HWND hWnd, bool windowed), (hWnd, windowed))
// Which should give(i want it to):
// void InitD3D(HWND hWnd, bool windowed){engine->InitD3D(hWnd, windowed);}
// But it may give: InitD3D((HWND hWnd, bool windowed)){engine->InitD3D((hWnd, windowed));}
// Or something similar or not...基本的话也是如此,我怎样才能在一个参数中传递多个参数,而不把它搞砸……
谢谢
发布于 2012-12-14 04:46:34
#define CALL(v, look, param, expect) v param {look expect;}
namespace foo {
void bob(int x, int y) {}
}
CALL(void bob, foo::bob, (int x, int y), (x,y))
int main() {
bob(7,2);
}我建议不要使用这种技术。
发布于 2012-12-14 04:53:47
在中传递多个参数的最简单方法是使用结构。
示例:
typedef struct{
int arg1;
std::string arg2;
int arg3;
} fn_args;
void bob( fn_args a )
{
//access them using a.arg1, a.arg2, etc.
}编辑:您提到了VA_ARGS。当您想要传递的参数数量是可变的时,使用它。通常情况下,不需要使用VA_ARGS就可以解决大多数问题。
您可能想要了解的另一种技术是Named Parameter Idiom,它更多的是不关心传递函数参数的顺序。由于您在这里尝试做的事情并不完全清楚,我给出了几种可能的方法。
https://stackoverflow.com/questions/13868039
复制相似问题