我已經爲Visual Studio和鐺定義這些宏,他們都編譯罰款如何使GCC將'arg,## __ VA_ARGS__'減少爲'arg'以將其用作單個宏參數?
#if defined(_MSC_VER)
# define _declare_func(...) PP_CAT(PP_CAT(_declare_func_, PP_NARG(__VA_ARGS__)),(__VA_ARGS__))
# define declare_func(...) _declare_func PP_LEFT_PAREN notused,##__VA_ARGS__ PP_RIGHT_PAREN
#else // clang version
# define _declare_func(...) PP_CAT(_declare_func_, PP_NARG(__VA_ARGS__))(__VA_ARGS__)
# define declare_func(...) _declare_func (notused,##__VA_ARGS__)
#endif
#define _declare_func_1(notused) void my_function()
#define _declare_func_2(notused, scope) void scope::my_function()
class MyClass
{
declare_func();
};
declare_func(MyClass) { }
PP_CAT是一個典型的多級CONCAT宏觀
PP_NARG計數的宏參數
PP_LEFT_PAREN和PP_RIGHT_PAREN數量減少到'('和')'
有什麼辦法可以用GCC來實現這個嗎? (我嘗試了兩個宏版本和GCC 5.2,兩者都無法編譯,因爲逗號似乎在宏分辨率期間傳播並且僅在預處理結束時被移除,使得PP_NARG總是減少到'2'而不是'1')
謝謝!
你救了我的一天!萬分感謝 !做了這項工作..我確實使用-std = C++ 11而不是std = gnu ++ 11。 – Juicebox