Constructor Functions  «Prev 

One Constructor and Two Purposes

In our mod_int example, one constructor could serve as both a general initializer and a default constructor:

inline  mod_int::mod_int(int i = 0){
  v = i % modulus; 
}

In computer programming languages the term default constructor refers to a constructor that is automatically generated in the absence of explicit constructors.
This automatically provided constructor is usually a constructor that does not contain default values. In the specification or discussion of some languages, default constructor may additionally refer to any constructor that may be called without arguments. Two cases arise here:
  1. either the constructor has null values or
  2. all of its parameters have default values.

The C++ standard describes the default constructor for a class as a constructor that can be called with no arguments (this includes a constructor whose parameters all have default arguments).