C++: allocate block of T without calling constructor

前端 未结 3 684
野趣味
野趣味 2021-02-01 04:01

I don\'t want constructor called. I am using placement new.

I just want to allocate a block of T.

My standard approach is:

T* data = malloc(sizeo         


        
3条回答
  •  终归单人心
    2021-02-01 04:42

    T* data = reinterpret_cast(operator new(sizeof(T) * num));

    Or just use std::vector and don't worry about these low-level memory details ;)

提交回复
热议问题