简体   繁体   中英

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.

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.

Therefore, the correct template instantiation must be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM