An operator == whose parameters are non-const references
Posted
by Eduardo León
on Stack Overflow
See other posts from Stack Overflow
or by Eduardo León
Published on 2008-12-19T15:39:24Z
Indexed on
2010/04/07
22:43 UTC
Read the original article
Hit count: 282
I this post, I've seen this:
class MonitorObjectString: public MonitorObject {
// some other declarations
friend inline bool operator==(/*const*/ MonitorObjectString& lhs,
/*const*/ MonitorObjectString& rhs)
{ return lhs.fVal==rhs.fVal; }
}
Before we can continue, THIS IS VERY IMPORTANT:
- I am not questioning anyone's ability to code.
- I am just wondering why someone would need non-const references in a comparison.
- The poster of that question did not write that code.
This was just in case. This is important too:
- I added both
/*const*/
s and reformatted the code.
Now, we get back to the topic:
I can't think of a sane use of the equality operator that lets you modify its by-ref arguments. Do you?
© Stack Overflow or respective owner