lundi 3 juillet 2017

Differnace between "delete p" and "p->~MyClass()"

class MyClass
{
    public:
        MyClass()
        {
            std::cout << "MyClass Constructor" << std::endl;
        }

        ~MyClass()
        {
            std::cout << "MyClass Destructor" << std::endl;
        }
};

int main()
{
    MyClass* p = new MyClass();
}

What is the difference between calling p->~MyClass(); OR delete p;

Both call the destructor.

Aucun commentaire:

Enregistrer un commentaire