new(p) T is placement new. Its function is to construct the object T on the storage area pointed to by p. Generally, new will first apply for a storage area, and then construct an object on the applied storage area.
T() is value initialization and is not equivalent to T. The function is to initialize the object through the default constructor or 0-initialize the object according to the type T.
int *p = new int();
assert(*p==0);
PS: I made a mistake before. int a(); will be parsed by the compiler into a function declaration instead of a variable declaration.
new(p) T
is placement new. Its function is to construct the object T on the storage area pointed to by p. Generally, new will first apply for a storage area, and then construct an object on the applied storage area.T()
is value initialization and is not equivalent toT
. The function is to initialize the object through the default constructor or 0-initialize the object according to the type T.PS: I made a mistake before.
int a();
will be parsed by the compiler into a function declaration instead of a variable declaration.