In this case, the lines are equivalent; there is no difference in work.
However, be careful - this does not mean that such lines are ALWAYS equivalent. If your data type is a POD (i.e. a simple structure:
struct Foo { int a; float b; };
Then new Foo creates an uninitialized object, and new Foo() calls the value initialization constructor, the value of which initializes all fields, i.e. sets in this case the value 0.
Since in such cases it is easy to accidentally call new Foo() , forget to initialize the objects (this is great!), And then accidentally make your own non-POD class (in this case, the value will not be initialized and the object will be uninitialized again), a little better always invoke new Foo (although this causes a warning in some versions of MSVC).
source share