I need to determine whether an element is the same as the one I’m passing by reference.
In the function Belongs I need to compare equality between d is and an element of a stored in a dynamic list:
struct Nodo{ Dominio dominio; Rando rango; Nodo* next; };
typedef Nodo* ptrNodo;
ptrNodo pri;
template<class Dominio, class Rango>
bool DicListas<Dominio,Rango>::Belongs(const Dominio &d)
{
bool retorno = false;
if(!EsVacia())
{
ptrNodo aux=pri;
while(aux!=NULL)
{
if(aux->dominio==d)//-------> THIS CLASS DOESN'T KNOW HOW TO COMPARE THE TYPE DOMINIO.
{
retorno = aux->isDef;
}
aux = aux->sig;
}
}
return retorno;
}
Whatever type argument you provide for the type parameter
Dominio, you’ve to overloadoperator==for that type.Suppose, you write this:
then you’ve to overload
operator==for the typeAas:Also note that it should be
publicif it’s a member function, and better make itconstfunction as well, so that you can compare const objects of typeA.Instead of making it member function, you can make
operator==a non-member function as well:I would prefer the latter.