Explicitly instantiating variadic constructor: template-id does not match any template declaration

411 views Asked by At

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.

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*);
1

There are 1 answers

0
Sam Varshavchik On BEST ANSWER

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.

Therefore, the correct template instantiation must be:

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