Deleting an object in C++

前端 未结 6 1965
清酒与你
清酒与你 2021-02-01 03:56

Here is a sample code that I have:

void test()
{
   Object1 *obj = new Object1();
   .
   .
   .
   delete obj;
}

I run it in Visual Studio, an

6条回答
  •  萌比男神i
    2021-02-01 04:24

    Isn't this the normal way to free the memory associated with an object?

    Yes, it is.

    I realized that it automatically invokes the destructor... is this normal?

    Yes

    Make sure that you did not double delete your object.

提交回复
热议问题