C++ placement new

前端 未结 5 797
我在风中等你
我在风中等你 2020-12-01 20:01

Sorry if this question will sound stupid, but I\'m just starting to learn C++ and there is something confusing me about the placement new

I\'ve been reading C++ Prim

5条回答
  •  抹茶落季
    2020-12-01 20:33

    There are no stupid questions.

    It uses char probably because it makes you think about raw bytes (char is usually 1 byte long). The last line on the code is not allocating memory, it just places a double array over the mentioned buffer. If it was an object, it would also call the constructor. Yes, the char array gets overwritten.

提交回复
热议问题