gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:04:44 25 4
gpt4 key购买 nike

我正在尝试制作一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com