0

在 C++ 中,当我尝试扩展参数包时,它给了我错误

“参数包没有用'...'扩展”和“错误:预期的';' 在 '...' 标记之前"

帮助将不胜感激。我使用 mingw 8.2.0。

代码:

#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);
}
4

1 回答 1

2

你的方式std::cout.operator<< (oneoperand)std::cout.operator<<( operand1, operand2, ...)。你应该使用类似下面的东西

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

        ((std::cout << args), ..., (std::cout << endl));
    }
};
于 2020-04-12T12:19:40.583 回答