Charles and Michael Burr both identified that the second declaration was in fact a function prototype and not an instantiation of A
.
As for possible reasons why your first code snippet did not work, you would get a compilation error in this situation when:
- Class
A
inherits from a base class that has no default constructor; OR
- Class
A
contains objects of types that have no default constructor; OR
- Class
A
contains reference members;
AND
You have provided a default constructor which omits one or more of these subobjects from its initialiser list.
All of these subobjects need some way to be initialised, and the default constructor produced by the compiler won't do it. Note that in all cases you need to initialise them in the initialiser list, not the body of the constructor.