I'm trying to expand arguments to a variadic function. Code below works perfectly fine
template<typename T>
int printMy (const T& f)
{
cout << f << endl;
}
template<typename... Types>
void print (Types... args)
{
auto i = {printMy(args)...};
}
int main() {
std::string s("world");
print(7.5, "hello", s);
return 0;
}
However, I don't really want to return anything from the function. I actually want it to be void. However, when I have code like below, it doesn't work
template<typename T>
void printMy (const T& f)
{
cout << f << endl;
}
template<typename... Types>
void print (Types... args)
{
{printMy(args)...};
// same thing if I remove the brackets
// printMy(args)...;
}
It gives me an error on the line "{printMy(args)...};". The error is "Expression contains unexpanded parameter pack 'args'"