Constructor with Default Arguments in C++

It is possible in C++ to define constructors with default arguments. For example, the constructor integer(), defined in the previous section (Constructors in C++), can be defined as follows:

The default value of the argument y is 3. Thus, the statement:

assigns the value 1 to x variable and 3 to y (by default).

However, the statement:

assigns 1 to x and 5 to y. The actual parameters, when specified, overrides the default value.

Note: The missing arguments must be the trailing ones.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *