previous | start | next

## Constructors with Parameters (Syntax 6.4 : Constructors with Field Initializer List)

Syntax 6.4 : Constructors with Field Initializer List
    Class_name::Class_name(parameters):field1(expression), ..., fieldn(expression){  statements
    }
Example: |
    Point::Point(double xval, double yval):

     x(xval), y(yval)
    {
    }
Purpose: | Supply the implementation of a constructor, initializing data fields before the body of the constructor.

- The syntax above is an alternate, and more efficient, way to initialize data field, but many programmers find it confusing.
- This syntax is necessary to construct objects of classes that don't have a default constructor.

previous | start | next