• Advertisement
Sign in to follow this  

Question about == overloading

This topic is 4709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i dont understand this The two overloaded assignment operators reference the special keyword this. When we write String name1( "orville" ), name2( "wilbur" ); name1 == "Orville Wright"; this points to name1 within our assignment operator. bool String::operator==(const String &rhs){ if(_size != rhs._size) return false; return strcmp(_string, rhs._string) ? false : true; } Does this mean when the == operator function is called, the _size refers to name1, and any overloaded operator will result in the function being called with a this reference and the right hand operator?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Gink
_size refers to name1, and any overloaded operator will result in the function being called with a this reference and the right hand operator?

Yes, pretty much.

Your question was not very clear, though, so I may be wrong [smile].

Where you say "any", this is only the case for most operators. Some operators have more than one argument, some operators have no arguments. Globally defined operators do not have a "this", and it must be provided as an extra argument.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement