Example of a Conversion Function


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

The following code fragment shows a conversion function called operator int():

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

class Y
{
      int b;
public:
      operator int();
};
Y::operator int() {return b;}

void f(Y obj )
{
      // each value assigned is converted by Y::operator int()
      int i = int(obj);
      int j = (int)obj;
      int k = i + obj;
}