If i have a class like as below.
class A {
int data;
};
A a; // Case1: calling explicit Default constructor
A b(); // Case2: Calling implicit default constructor
What is the difference between Case1 and Case2?
If i have a class like as below.
class A {
int data;
};
A a; // Case1: calling explicit Default constructor
A b(); // Case2: Calling implicit default constructor
What is the difference between Case1 and Case2?
A b();
it does not define an object, it declares a function which returns type A
, It's also well known as most vexing parse.
A b(); // Case2: Calling implicit default constructor
The comment is incorrect. A b();
is a function declaration (The function is called b
and returns an object of type A
and you intend to define the function later) not an object definition.
Case 1:
A a; // Case1: calling explicit Default constructor
Calls the implicit default constructor, since you hadn't provided one in the class.
Case 2:
A b(); // Case2: Calling implicit default constructor
It is the function decleration say "b" is the function name and it takes no argument and returns A object.
Hope it helps.