C++ std::阵列Can';t比较以my class为元素的两个数组

C++ std::阵列Can';t比较以my class为元素的两个数组,c++,stdarray,C++,Stdarray,当我使用=运算符编译器比较它们时,我有两个std::数组大小相同,存储的元素类型相同(我编写的一个类)。运算符编译器抛出此错误:..\include\xutility(2919):错误C2672:'operator\uu subrogate\u func':未找到匹配的重载函数 我试着比较两个数组和向量作为它们的元素,这是有效的,但是比较数组和我写的任何类,我得到了那个错误 测试等级: class Class { int i; public: Class() {} C

当我使用
=
运算符编译器比较它们时,我有两个std::数组大小相同,存储的元素类型相同(我编写的一个类)。运算符编译器抛出此错误:
..\include\xutility(2919):错误C2672:'operator\uu subrogate\u func':未找到匹配的重载函数

我试着比较两个数组和向量作为它们的元素,这是有效的,但是比较数组和我写的任何类,我得到了那个错误

测试等级:

class Class {

    int i;

public:
    Class() {}
    Class(const Class& other) {}
    Class(Class&& other) {}
    ~Class() {}

    Class operator= (const Class& other) {}
    Class operator= (Class&& other) {}

    BOOL operator== (const Class& other) {}

};
比较:

   std::array<Class, 3> a0 = {};
   std::array<Class, 3> a1 = {};

      if (a0 == a1)
        "COOL";

如果查看
std::array
的定义,您会注意到它是为常量数组定义的。这意味着您只能以const的形式访问元素,而您的
类的
操作符==
不能这样做

将其更改为将其作为常量:

BOOL operator== (const Class& other) const { /*...*/ }
                                     ^^^^^
此时,您可能希望返回
bool
,而不是
bool

bool operator== (const Class& other) const { /*...*/ }

为什么返回的是
BOOL
而不是
BOOL
,为什么函数中没有return语句?因为您不是在比较
a0
a1
,而是数组。@Eli Sadoff a1和a0是数组lol@LorenceHernandez我知道。运算符被重载为
Class
而不是
std::array
@user3196144,那么
BOOL
肯定与
BOOL
不同。它是
int
的一个typedef。该链接指向您的一个答案,该答案与问题无关,与
操作符==
的实际定义无关。这是故意的吗?@Rakete1111不,这一定是复制粘贴错误。编辑。谢谢
bool operator== (const Class& other) const { /*...*/ }