Methods declared as const
can only call other const
methods. They cannot non-const methods. In your case method operator ==
is declared as const
. From inside of operator ==
you are attempting to call method Element
, which is non-const. This is your error.
Moreover, both Element
calls in
if (eq.Element(i) != Element(i))
are invalid. The first call is invalid since eq
is a const
reference, meaning that you cannot call any non-const methods through it. The second call is invalid for the reasons described above.
Either declare your Element
method as const
or provide a second, const
version of Element
in addition to the non-const one. I see that your element returns its result by value, which means that you can simply declare it as const
.