I'm trying to forward my tail from parser
to add_option
, but GCC won't allow this:
// Templated constructor
template <typename H = std::string, typename... T>
parser(H head, T... tail) {
/* Add an option */
add_option(std::forward<T>(tail)...);
}
// Base case
void add_option(std::string head) {
/* Add an option */
}
// Recursive case
template <typename H = std::string, typename... T>
void add_option(H head, T... tail) {
add_option(tail...);
}
Instead, GCC gives me this error:
parser.h: In instantiation of ‘void parser::add_option(H, T ...) [with H = const char*; T = {}]’:
parser.h:16:4: required from ‘parser::parser(H, T ...) [with H = const char*; T = {const char*}]’
parser.cpp:7:26: required from here
parser.h:24:4: error: no matching function for call to ‘parser::add_option()’
add_option(tail...);
^
parser.h:24:4: note: candidates are:
parser.h:18:8: note: void parser::add_option(std::string)
void add_option(std::string head) {
^
parser.h:18:8: note: c1andidate expects 1 argument, 0 provided
parser.h:22:8: note: template<class H, class ... T> void parser::add_option(H, T ...)
void add_option(H head, T... tail) {
^
parser.h:22:8: note: template argument deduction/substitution failed:
parser.h:24:4: note: candidate expects 2 arguments, 0 provided
add_option(tail...);
^
Makefile:2: recipe for target 'parser' failed
make: *** [parser] Error 1
Can anybody tell me what I'm doing wrong here? How can I fix this?