Declaring Objects with Default Constructor
-
Hello Everyone, In c++, when declaring objects using the default constructor why are we not allowed to use the parentheses? For example: Date birthday; vs. Date birthday(); // WRONG!! It seems like allowing the parentheses would keep the syntax of the declaration in sync with when we are using a constructor other than the default such as Date birthday(10, 4, 2000); Seems like there is a reason for everything in c++ so just wondering. Thanks.
-
Hello Everyone, In c++, when declaring objects using the default constructor why are we not allowed to use the parentheses? For example: Date birthday; vs. Date birthday(); // WRONG!! It seems like allowing the parentheses would keep the syntax of the declaration in sync with when we are using a constructor other than the default such as Date birthday(10, 4, 2000); Seems like there is a reason for everything in c++ so just wondering. Thanks.
yadrif wrote:
Date birthday();
That's a declaration for function
birthday
that takes no parameters and returns aDate
.
-
yadrif wrote:
Date birthday();
That's a declaration for function
birthday
that takes no parameters and returns aDate
.
-
Hello Everyone, In c++, when declaring objects using the default constructor why are we not allowed to use the parentheses? For example: Date birthday; vs. Date birthday(); // WRONG!! It seems like allowing the parentheses would keep the syntax of the declaration in sync with when we are using a constructor other than the default such as Date birthday(10, 4, 2000); Seems like there is a reason for everything in c++ so just wondering. Thanks.
using the default constructor to use the parentheses int i = int(); char c = char(); Data birthday = Data();