Example of Conversion by Constructor


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

The following example shows conversion by constructor:

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

class Y
{
      int a,b;
      char* name;
public:
      Y(int i);
      Y(const char* n, int j = 0);
};
void add(Y);
// ...
void main ()
{
      // code                     equivalent code
      Y obj1 = 2;              // obj1 = Y(2)
      Y obj2 = "somestring";   // obj2 = Y("somestring",0)
      obj1 = 10;               // obj1 = Y(10)
      add(5);                  // add(Y(5))
}