jeudi 11 juillet 2019

Overload the opposite of the negation operator? [duplicate]

This question already has an answer here:

Overloading the negation operator is simple:

bool MyClass::operator!() const
{
    //return whatever comparison needs to be done
}

Then I can write:

MyClass a;
if(!a)
{
    //Do something
}

But I want to be able to write:

if(a)
{
    //Do something
}

How can I do this?

Aucun commentaire:

Enregistrer un commentaire