I believe that my operator overloading is not working for one of my two datatypes. MY program works with an int datatype but not with my defined class students. students is a tree of pointers so this might be my problem. I discovered this problem when my search function wasn't functioning as planned. I'm hoping to get some advice as to what I am doing wrong with my overloaded operators.
struct Students{
char lastName[20];
char firstName[20];
int IDnumber;
Students();
bool operator == (const Students);
bool operator > (const Students);
bool operator < (const Students);
friend ostream& operator << (ostream& stream, const Students* students);
};
template <class DataType>
TNode<DataType>* BST<DataType>::bstSearch(DataType search)
{
TNode<DataType>* y = root;
while (y!=NULL && search != y->data)
{
if (search < y->data)
{
y = y->left;
}
else
{
y = y->right;
}
}
return y;
}
here is my overloader code
friend bool operator == (const Students& lh, const Students& rh);
friend bool operator > (const Students& lh, const Students& rh);
friend bool operator < (const Students& lh, const Students& rh);
bool operator ==(const Students& lh, const Students& rh)
{
return lh.IDnumber == rh.IDnumber;
}
bool operator > (const Students& lh, const Students& rh)
{
return lh.IDnumber > rh.IDnumber;
}
bool operator < (const Students& lh, const Students& rh)
{
return lh.IDnumber < rh.IDnumber;
}
this is the tree objects I create
BST<Students*> stree;
BST<int> itree;