lundi 2 février 2015

Destructor explicit calling

In fallowing code , why p.destroy() ; is called with(.), why p->destroy() ; not used.



class Nonlocal {
public:
// ...
void destroy() { this−> ̃Nonlocal(); }
private:
// ...
̃ Nonlocal(); // destructor

};
// explicit destruction
// don’t destroy implicitly
void user()
{
Nonlocal x; // error : cannot destroy a Nonloca
X∗ p = new Nonlocal; // OK
// ...
delete p; // error : cannot destroy a Nonlocal
p.destroy(); // OK
}

Aucun commentaire:

Enregistrer un commentaire