我正在尝试编译下面的一段代码,我在专门用于std :: vector的行上得到一个错误,似乎传入的一个参数在某种程度上被假定为两个参数.它可能与角括号有关吗?
是否有一种特殊的方式/机制,通过这些参数可以正确地传递给宏?
#include <vector>
template<typename A>
struct AClass {};
#define specialize_AClass(X)\
template<> struct AClass<X> { X a; };
specialize_AClass(int) //ok
specialize_AClass(std::vector<int,std::allocator<int> >) //error
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
1 Line 55: error: macro "specialize_AClass" passed 2 arguments, but takes just 1
2 Line 15: error: expected constructor, destructor, or type conversion before 'int'
3 compilation terminated due to -Wfatal-errors.
Run Code Online (Sandbox Code Playgroud)