I have a templated class set up like so:
template<typename T>
class treeNode
{
public:
bool operator==(const treeNode<T>&) const;
bool operator>(const treeNode<T>&) const;
void print();
T field;
int key;
};
Using the > operator as an example of my problem, I have it overloaded like this:
template<typename T>
bool treeNode<T>::operator>(const treeNode<T>& node) const
{
if(field > node.field) return true;
else return false;
}
This operator works fine when I'm working with integers e.g. treeNode<int> nodeInt;
However, sometimes I need to work with C-style strings (char arrays) and I'm struggling to find a way that I can overload the operator and have it work for both datatypes. In order for it to successfully compare the two C-style strings, I thought I'd have to use strcmp();
so I'm not sure how to implement this and still have it work correctly with other datatypes such as integers. Also note that I am forced to use C-style strings, and cannot substitute these with std::string.
Any help would greatly be appreciated.