[英]Explicitly instantiating variadic constructor: template-id does not match any template declaration
I'm trying to explicitly instantiate a variadic constructor. 我正在尝试显式实例化可变参数构造函数。 This minimal example to print all arguments causes the same error I'm seeing on MinGW-w64 on 64 bit Win 7 with GCC 5.3.
这个打印所有参数的最小示例会导致我在使用GCC 5.3的64位Win 7上的MinGW-w64上看到相同的错误。
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*);
Let's ignore the parameter pack, for one moment: 让我们暂时忽略参数包:
template<typename Arg> stf(Arg &&args)
Pop quiz: which instantiation matches the above template. 弹出测验:与上面的模板匹配的实例。 Is it:
是吗:
template<char *> stf(char *);
or 要么
template<char *> stf(char *&&);
? ?
If you substitute char *
everywhere the template type appears in the template, you'll obviously end up with the second version as the right answer. 如果在模板类型出现在模板的任何地方都用
char *
代替,显然您会得到第二个版本作为正确答案。
Therefore, the correct template instantiation must be: 因此,正确的模板实例化必须是:
template stf::stf<char*,char*>(char* &&,char* &&);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.