你好,我想在类中存储模板参数,参见以下代码:
template<typename... Args>
class Test {
private:
Args... args;
public:
Test(Args... args) {
this->args = args;
}
}
但是我得到错误:
main.cc:4:9: error: expected unqualified-id before ‘...’ token
4 | Args... args;
当我删除点时,它显示:
main.cc:4:10: error: parameter packs not expanded with ‘...’:
4 | Args args;
通常的解决方案是简单地使用元组:
template<typename... Args>
class Test {
private:
std::tuple<Args...> args;
public:
Test(Args... args) : args{std::move(args)...} {}
};