C++ placement new

前端 未结 5 792
我在风中等你
我在风中等你 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:18

    char buffer[BUF]; is just some memory. There's no type information attached to the bytes composing buffer. Only the compiler knows, that this memory region is supposed to hold characters. You could use any type, even double:

    double buffer[BUF];
    double *pd1 = new (buffer) double[N];
    

提交回复
热议问题