calling the default constructor

The second one is declaring a function a() that returns a base object. :-)


base a declares a variable a of type base and calls its default constructor (assuming it's not a builtin type).

base a(); declares a function a that takes no parameters and returns type base.

The reason for this is because the language basically specifies that in cases of ambiguity like this anything that can be parsed as a function declaration should be so parsed. You can search for "C++ most vexing parse" for an even more complicated situation.

Because of this I actually prefer new X; over new X(); because it's consistent with the non-new declaration.

Tags:

C++