c++ - std::array Can't compare between two arrays with my class as its element -
i have 2 std::array same size , store same element type (a class wrote) when compare them using ==
operator compiler throws error: ...\include\xutility(2919): error c2672: 'operator __surrogate_func': no matching overloaded function found
.
i tried comparing tow arrays vectors elements , worked comparing arrays class write i'm getting error.
test class:
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) {} };
comparison:
std::array<class, 3> a0 = {}; std::array<class, 3> a1 = {}; if (a0 == a1) "cool";
error i'm getting:
...\include\xutility(2919): error c2672: 'operator __surrogate_func': no matching overloaded function found
if @ std::array
's definition of operator==
, you'll notice it's defined const arrays. means can access elements const, class
's operator==
doesn't do.
change take implicit const:
bool operator== (const class& other) const { /*...*/ } ^^^^^
while @ it, want return bool
instead of bool
:
bool operator== (const class& other) const { /*...*/ }
Comments
Post a Comment