c++ - 没有运算符的类型 vector 的实例化=

标签 c++ vector

我正在尝试制作一个 DataEntry 对象的 vector ,这些对象的 operator= 已被禁用:

using Row = vector<DataEntry>;

class DataTable {
public:
    vector<Row> data;
};

这会导致错误

in instantiation of member function 'std::__1::vector<std::__1::vector<DataEntry, std::__1::allocator<DataEntry> >, std::__1::allocator<std::__1::vector<DataEntry,
          std::__1::allocator<DataEntry> > > >::operator=' requested here
    class DataTable {

有没有办法解决这个问题并在不意外使用 operator= 的情况下制作 vector ?

最佳答案

Is there a way to get around this and make the vector without accidentally using the operator=?

不,没有。

T 的要求之一 std::vector是:

T must meet the requirements of CopyAssignable and CopyConstructible.

如果您能够使用支持 C++14 或 C++17 的编译器,则要求会稍微宽松一些。

The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements.

关于c++ - 没有运算符的类型 vector 的实例化=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49501130/

相关文章:

c++ - Qt SQL - 配置数据库连接

c++ - 在资源 DLL 之间切换

audio - 3D空间中声源位置的计算

c++ - 指向 vector : getting segmentation fault 的指针

c++ - 在 C++ 中将大数据 vector 写入/读取到二进制文件

c++ - 遍历 vector 会导致错误,但标准 for 循环不会

c++ - 删除最后一个子串

c++ - 从非模板基派生模板类

algorithm - 如何将 "snap"方向(2D)矢量指向罗盘(N、NE、E、SE、S、SW、W、NW)?

c++ - 在 C++ 中访问 Lua 函数的返回值,反之亦然