A strange problem!

if( xa.S[i]==ya.S[i] && xa.B[i]==ya.B[i] ) {//do something}

When I want to compile the above statement, it gives "passing ‘const BC_c’ as ‘this’ argument of ‘bool BC_c::operator==(const BC_c&)’ discards qualifiers [-fpermissive]" error message.

but if I simply change to the following, the compiling goes through, got confused.

1
2
3
        segment_c SX(xa.S[i]), SY(ya.S[i]);
	BC_c BCX(xa.B[i]), BCY(ya.B[i]);
	if( SX==SY && BCX==BCY ) {//do something} 



Please help out, thanks!
Last edited on
Looks like your operator== of class BC_c is not marked as const and your xa.B array is const.
Thanks, NiiNiPaa,

No, it is marked as const
You mean it looks like bool BC_c::operator==(const BC_c&) const?
Can you double check?
Why do you have a const in the end? What is that for?
It means that this function will not change the object state, which allows it to be called on const objects.

Member functions are internally implemented as freestanding functions with implicif first parameter this. Your operator can be written as:
bool BC_c@operator==(BC_c* this, const BC_c&)
Qualifiers applied to member functions, applies those modifiers to this parameter.
So bool BC_c::operator==(const BC_c&) const
Will be transformed to
bool BC_c@operator==(const BC_c* this, const BC_c&)
Last edited on
That make sense, thanks alot!
Topic archived. No new replies allowed.