Having the following operator declared in a string class, would it be correct to use it in a match class as follows?
Operator:
bool CCadena::operator==(const CCadena& obj) const {
return strcmp(m_pText, obj.m_pText) == 0;
}
function:
if(m_nomLocal==nomEquip)
{
return true;
}
else if(m_nomVisitant==nomEquip)
{
return true;
}
else
{
return false;
}
I need to compare if the content of the nomlocal and visitor variables are equal to the nomEquip parameter and return true if so and false otherwise.
If what you are interested in is knowing if it
nomEquip
is equivalent tom_nomLocal
orm_nomVisitant
and assuming that the three variables are of typeCCadena
, it would be more natural to leave it like this:or this way:
The two options are equivalent, of course your method would work too, but it's more repetitive and therefore error prone.
It seems to me that
m_nomLocal
,m_nomVisitant
andnomEquip
are * variablesconst char
while the operator==
I defined is used to compare objectsCCadena
. Its operator==
compares the membersm_pText
of theCCadena
s and therefore does not serve to compare m_local, m_nomVisitant and nomEquip directly.