By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

Operation Overload- Comparison operator: ==

P: 46
Simply put, I need to know how to overload a comparison operator like ==. Assuming I have a function that compares to of my objects: obj1, and obj2. This function returns 0 if obj1 and obj2 are equal. Google returns nothing, you are my only hope xD
Thanks,
Austen :-)
Mar 11 '07 #1
Share this Question
Share on Google+
2 Replies


Ganon11
Expert 2.5K+
P: 3,652
You need a function header like this:

Expand|Select|Wrap|Line Numbers
  1. bool yourClass::operator==(const yourClass& other) {
  2.    return this->someValue == other.someValue;
  3. }
Obviously, you'll have to fill in the portions for your own class.
Mar 11 '07 #2

P: 46
You need a function header like this:

Expand|Select|Wrap|Line Numbers
  1. bool yourClass::operator==(const yourClass& other) {
  2.    return this->someValue == other.someValue;
  3. }
Obviously, you'll have to fill in the portions for your own class.
Thanks :-)
Works just fine
Mar 11 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.