jeudi 14 mai 2015

Is it safe to use a possibly nullptr pointer in an if statement after checking if it's nullptr in the same statement? [duplicate]

This question already has an answer here:

Consider this piece of code:

MyObject* ptr = getObjectInstanceOrNullptr();
if (ptr != nullptr && ptr->isConditionTrue())
    //Do something

Is it safe?

Aucun commentaire:

Enregistrer un commentaire