0

In c++, when I try to expand a parameter pack, it gives me the errors

"parameter packs not expanded with '...'" and "error: expected ';' before '...' token"

Help would be very appreciated. I use mingw 8.2.0.

Code:

#include <iostream>
using namespace std;

template <class... Types>
class Test {
    Test(Types... args) {
        cout << args... << endl;
    }
};

int main() {
    Test<string, int> test("this is a test", 3);
}
asmmo
  • 6,922
  • 1
  • 11
  • 25
CrazyVideoGamer
  • 754
  • 8
  • 22
  • 2
    Does this answer your question? [What is the easiest way to print a variadic parameter pack using std::ostream?](https://stackoverflow.com/questions/27375089/what-is-the-easiest-way-to-print-a-variadic-parameter-pack-using-stdostream) – fas Apr 12 '20 at 11:53
  • Expansions don't use `<<` as delimiters. You need a fold expression. – L. F. Apr 12 '20 at 11:54

1 Answers1

2

Your way makes std::cout.operator<< (oneoperand) be std::cout.operator<<( operand1, operand2, ...). You should use a thing like the following

template <class... Types>
struct Test {
    Test(const Types &... args) {

        (std::cout << ... << args) << std::endl;
    }
};
asmmo
  • 6,922
  • 1
  • 11
  • 25