Zie*_*ezi 2 c++ oop malloc templates new-operator
以下是实现创建对象的类的示例:
template <class T>
struct MallocCreator {
static T* Create() {
void* buf = std::malloc(sizeof(T));
if (!buf) return 0;
return new(buf) T;
}
};
Run Code Online (Sandbox Code Playgroud)
通过使用malloc和new操作员.
new上述语法的作用是什么,究竟是什么?