mardi 23 juillet 2019

Why can an object be the conditional in an if statement, please explain [duplicate]

This question already has an answer here:

I've been looking over some code in C++ and came across an object being the boolean conditional for an if statement. This is confusing to me as it does not seem to fulfill the true/false criteria needed for if statements. I could understand if the statement was checking for null but the follow code does not make sense to me.

if(!mObject)
{
    mObject = new Object();
}

Can someone explain why you can do this?

BTW, the code works when it is run.

Aucun commentaire:

Enregistrer un commentaire