C++ overloading comparative operators for a MyString class
- by Taylor Gang
bool operator == (const MyString& left, const MyString& right)
{
if(left.value == right.value)
return true;
else return false;
}
bool operator != (const MyString& left, const MyString& right)
{
if(left == right)
return false;
else
return true;
}
bool operator < (const MyString& left, const MyString& right)
{
if(strcmp(left.value, right.value) == -1)
return true;
else
return false;
}
bool operator > (const MyString& left, const MyString& right)
{
if(strcmp(left.value, right.value) == 1)
return true;
else
return false;
}
bool operator <= (const MyString& left, const MyString& right)
{
if(strcmp(left.value, right.value) == -1 || strcmp(left.value, right.value) == 0)
return true;
else
return false;
}
bool operator >= (const MyString& left, const MyString& right)
{
if(strcmp(left.value, right.value) == 1 || strcmp(left.value, right.value) == 0)
return true;
else
return false;
}
So these are my implemented comparison operators for my MyString class, they fail the test program that my professor gave me and could use some direction. Thanks in advance for any and all help I receive.