My question is on Default Constructors in C++. After passing the above two objects separately, I found that (a) A obj1, was detected as Default Constructor, and the constructor defining it was executed. (b) A obj1(), was not detected as Default Constructor. It matched with none of the constructors.
In both the cases, there is no argument passed. Then why is that only (a) is set for Default Constructor and not the second, i.e (b).
Leta there be a class named A. What is the difference between passing the following two objects: (a) A obj1 and (b) A obj1()?
The difference is that A obj1;
declares an object obj1
of type A
. While A obj1();
declares a function obj1
which takes no arguments and returns an A
- it does not create an object.