Jump to content
  • Advertisement
Sign in to follow this  
Gink

Question about == overloading

This topic is 4797 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!