Constructors
You define a constructor the same way that you define any other member function, except for two points:
- a constructor must have the same name as the class
-
- a constructor definition cannot return a value; moreover, no type, not even void, can be given at the start of the function prototype or in the function header
class_name object_name(arguments_for_constructor);
BankAccount account1(100, 2.3);
Syntax: (for an explicit constructor call)
object = constructor_name(arguments_for_constructor);
account1 = BankAccount(100, 2.3);