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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -