signature of equality operators

Duss Pirmin pirmin at ...321...
Sat May 16 01:34:26 CEST 2015


Hello

I have a the following code:

#include <vector>

class myClass {
   private:
     std::vector<Genode::Trace::Subject_id>  mSubjectList;

   public:
     bool hasSubjectId(Genode::Trace::Subject_id aSubjectId) const {
       return std::find(mSubjectList.begin(), mSubjectList.end(),  
aSubjectId) != mSubjectList.end();
     }
}

If I try to compile it, I get the following error:
/home/pirmin/Documents/genode/genode/contrib/stdcxx-fadf4f6ba436fe4846572f00bf057c5ef290c25b/include/stdcxx/bits/stl_algo.h:168:4: error: passing ‘const Genode::Trace::Subject_id’ as ‘this’ argument of ‘bool Genode::Trace::Subject_id::operator==(const Genode::Trace::Subject_id&)’ discards qualifiers  
[-fpermissive]

In base/trace/types.h the signature of the operator==() for Subject_id  
is defined as follows:
bool operator == (Subject_id const &other) { return id == other.id; }

Shouldnt it be?
bool operator == (Subject_id const &other) const { return id == other.id; }

Most recomendations on operator overloading, I have read, recommend this.

Best regards
Pirmin






More information about the users mailing list