Best way to write constructor of a class who holds a STL container in C++11

前端 未结 3 1506
[愿得一人]
[愿得一人] 2020-12-31 14:54
class Foo {
  std::vector data_;
};

Say Foo can only be constructed by make a copy (technically I mean a copy or move)

3条回答
  •  一整个雨季
    2020-12-31 15:17

    class Foo {
      using data_t = std::vector;
      data_t data_;
    public:
      constexpr Foo(data_t && d) noexcept : data_(std::forward(d)) {}
    };
    

提交回复
热议问题