On Aug 16, 10:41 am, Joe Greer <jgr...@doubletake.comwrote:
Travis wrote:
Is it possible to have multiple overloaded == operators for a given
class?
So that I can say two objects are == if they share the same name but
also two objects are equal if they share the same unique int code?
To me it makes sense to allow multiple ones but I have never bumped
into it before.
Not exactly. You can only overload functions based upon the types of
their arguments. In this case you don't need that. The way you do this
is by using an || in your == operator. Something like:
class A
{
public:
bool operator==(const A & a) const
{
return m_Id == a.m_Id || m_Name == a.m_Name;
}
private:
int m_Id;
std::string m_Name;
};
Hope that helps.
joe
Thanks for the help. Maybe I am going about it the wrong way. So
basically what I'm wanting to do, is get a node in the tree based on
some criteria. I wanted tree to remain as reusable as possible so I
would like to avoid modifying it (it's a template, etc.).
So the tree is full of myNodeType I would like to be able to say
myNodeType *foundNode = MenuTreeObj->findNode(ID); // find based on ID
- or -
myNodeType *foundNode = MenuTreeObj->findNode(unique_name); // find
based on name
Is that even practical? What I had been doing in the past (since the
== makes determination based on name).
myNodeType *tmp = new myNodeType("unique_name_to_be_found");
myNodeType *foundNode = MenuTreeObj->findNode(tmp);