マクロを使用していくつかの静的変数を作成しようとしています。
私の問題は、2つのパラメーターを使用してマクロを定義するにはどうすればよいかということです。最初のパラメーターはテンプレートで、2番目のパラメーターは静的変数です。テンプレートには複数のタイプが必要です。
例えば:
#define macro(x, y, z, v) x::y z = v;
int main(int argc, char *argv[]) {
// this works
macro(std::queue<int>, value_type, test, 4)
// this also works
std::pair<int, int>::first_type x = 3;
// this is produsing some compiler errors
macro(std::pair<int, int>, first_type, test2, 4)
return 0;
}
そしてこれを行うことさえ可能ですか?
ここにエラーがあります:
main.cpp(47) : warning C4002: too many actual parameters for macro 'macro'
main.cpp(47) : error C2589: 'int' : illegal token on right side of '::'
main.cpp(47) : error C2589: 'int' : illegal token on right side of '::'
main.cpp(47) : error C2143: syntax error : missing ',' before '::'
main.cpp(50) : error C2143: syntax error : missing ';' before '}'
main.cpp(51) : error C2143: syntax error : missing ';' before '}'
JoachimPileborgに触発されました
#define macro(x, y, z, v, ...) x<__VA_ARGS__>::y z = v;
...
// now it works
macro(std::pair, first_type, test2, 4, int, int)
thx Joachim