This question already has an answer here:
- c++ convert class to boolean 5 answers
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