3

如何创建具有类型成员的对象std::tuple

我试图编译这段代码。

  6 template <class ... T>
  7 class Iterator
  8 {
  9 public:
 10         Iterator(T ... args)
 11                 : tuple_(std::make_tuple(args))
 12         {
 13         }
 14 
 15 private:
 16         std::tuple<T ...> tuple_;
 17 };

但它无法编译并出现以下错误。

variadic.cpp: In constructor ‘Iterator<T>::Iterator(T ...)’:
variadic.cpp:11:33: error: parameter packs not expanded with ‘...’:
variadic.cpp:11:33: note:         ‘args’

代码有什么问题?

4

1 回答 1

11

args是可变参数的,因此您必须使用以下命令对其进行扩展...

: tuple_(std::make_tuple(args...))
//                           ^^^

你不需要make_tuple这个:

: tuple_(args...)
于 2013-10-27T17:06:57.837 回答