Trying to learn Variadic templates
and have no clue why this won't compile, the error is:
no matching constructor for initialization of 'test<>'
.
While we are at it, I like to ask a second question by clarifying my comments within the code.
template <typename ...Args> // this is just how Variadic template are defined
class test {
public:
int arr[sizeof...(Args)]; // this is packing or unpacking? why are
// dots outside of bracket?
test(Args... arg) // this is called packing?
: arr{arg...}{} // this is called un-packing?
};
int main(){
test<> t(1,2,3);
return 0;
}
Edit: seems like i need to do test <int, int, int>
, but why do I have to as this other example works as is:
template <typename ...Args>
int func(Args... arg)
{
int a[] = {arg...};
return sizeof...(arg);
}
int main(void)
{
std::cout << func(1,2,3,4,5,6) << std::endl;
return 0;
}
func doesn't need the <int, int ,int..
part.