954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Overloaded operator isn't used inside the declaration file

Hello,

I've written couple of overloaded operators in my file containing Set declarations. I want to use these operators within the declaration file. However it seems it isn't used. Instead it uses the standard operators.


e.g. i have two overloaded operators say <= and ==

bool Set::operator<=(const Set& b) const {
   //codes....
   return true;
}

bool Set::operator==(const Set& b) const {
   if(b.header <= header && header <= header)
       //codes....
   return true;
}


Inside my overload for == which I use <= it doesn't use my overloaded version of <= instead it uses the standard version. Do I have to write a certain way to use my overloaded operator? or is it some other problems?

ganmo
Light Poster
38 posts since Mar 2009
Reputation Points: 46
Solved Threads: 1
 

hmm.......i dont understand what exaclty your trying to do, please explain in a different way :P

stumpy798
Newbie Poster
18 posts since Apr 2009
Reputation Points: 10
Solved Threads: 5
 

I want to use my overloaded operator, inside another overloaded operator.

ganmo
Light Poster
38 posts since Mar 2009
Reputation Points: 46
Solved Threads: 1
 

Hello, bool Set::operator==(const Set& b) const { if(b.header <= header && header <= header) //codes.... return true; } [/code]

Inside my overload for == which I use <= it doesn't use my overloaded version of <= instead it uses the standard version. Do I have to write a certain way to use my overloaded operator? or is it some other problems?

Inside your operator==, you're comparing header, not Set. You'd have to have an overload for whatever type b.header is.

boblied
Newbie Poster
24 posts since Mar 2009
Reputation Points: 36
Solved Threads: 9
 

aha, stupid of me....
thanks for the help :)

ganmo
Light Poster
38 posts since Mar 2009
Reputation Points: 46
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You