In what way is ::operator new[]() different than ::operator new()?

前端 未结 2 1051
清酒与你
清酒与你 2021-01-21 04:11

I need to construct an array of objects from a previously allocated block of memory. However, I cannot understand in what way ::operator new[]() is different from <

2条回答
  •  借酒劲吻你
    2021-01-21 04:48

    You're misusing the new.

    The point of using new [] is that it calls the constructor for each and every element of the array being allocated. delete[] does the same for the destructors.

    You're using placement new and manually calling the constructors and destructors, missing the whole point.

提交回复
热议问题