显式实例化可变参数构造函数:template-id 不匹配任何模板声明
Explicitly instantiating variadic constructor: template-id does not match any template declaration
我正在尝试 explicitly instantiate a variadic constructor. This minimal example to print all arguments 导致我在 MinGW-w64 上看到的相同错误,在 64 位 Win 7 和 GCC 5.3 上。
struct stf {
template<typename... Args> stf(Args&&... args){
using expand_type = int[];
expand_type{(print(args), 0)... };
}
};
//error on next line:
//template-id 'stf<char*, char*>' for 'stf::stf(char*, char*)'
//does not match any template declaration
template stf::stf<char*,char*>(char*,char*);
暂时忽略参数包:
template<typename Arg> stf(Arg &&args)
突击测试:哪个实例化与上述模板匹配。是吗:
template<char *> stf(char *);
或
template<char *> stf(char *&&);
?
如果您在模板中出现模板类型的所有地方替换 char *
,您显然会以第二个版本作为正确答案。
因此,正确的模板实例化必须是:
template stf::stf<char*,char*>(char* &&,char* &&);
我正在尝试 explicitly instantiate a variadic constructor. This minimal example to print all arguments 导致我在 MinGW-w64 上看到的相同错误,在 64 位 Win 7 和 GCC 5.3 上。
struct stf {
template<typename... Args> stf(Args&&... args){
using expand_type = int[];
expand_type{(print(args), 0)... };
}
};
//error on next line:
//template-id 'stf<char*, char*>' for 'stf::stf(char*, char*)'
//does not match any template declaration
template stf::stf<char*,char*>(char*,char*);
暂时忽略参数包:
template<typename Arg> stf(Arg &&args)
突击测试:哪个实例化与上述模板匹配。是吗:
template<char *> stf(char *);
或
template<char *> stf(char *&&);
?
如果您在模板中出现模板类型的所有地方替换 char *
,您显然会以第二个版本作为正确答案。
因此,正确的模板实例化必须是:
template stf::stf<char*,char*>(char* &&,char* &&);