Example of Explicitly Constructing an Object


/************************************************************************
*

In the following example, a constructor is used as an initializer to create a named object.

                                                                        *
************************************************************************/

#include <iostream.h>
class X
{
public:

      X (int, int , int = 0);  // constructor with default argument
private:
      int a, b, c;
      int f();
};
X::X (int i, int j, int k) { a = i; b = j; c = k; }

void main ()
{
X xobject = X(1,2,3);    // explicitly create and initialize
                         // named object with constructor call
}