2

我正在尝试显式实例化可变参数构造函数。这个打印所有参数的最小示例导致我在带有 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*);
4

1 回答 1

3

让我们暂时忽略参数包:

template<typename Arg> stf(Arg &&args)

小测验:哪个实例化与上述模板匹配。是吗:

template<char *> stf(char *);

或者

template<char *> stf(char *&&);

?

如果您char *在模板中出现的任何地方替换模板类型,您显然最终会得到第二个版本作为正确答案。

因此,正确的模板实例化必须是:

template stf::stf<char*,char*>(char* &&,char* &&);
于 2016-12-29T00:09:03.433 回答