C++ overloading comparative operators for a MyString class
Posted
by
Taylor Gang
on Stack Overflow
See other posts from Stack Overflow
or by Taylor Gang
Published on 2012-03-28T05:13:47Z
Indexed on
2012/03/28
5:29 UTC
Read the original article
Hit count: 177
c++
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.
© Stack Overflow or respective owner