Conversion Functions
C++ allows allows the creation of custom conversion functions. A
conversion function converts a class into a type compatible with that
of the rest of the expression. Conversion functions allow the use of
an object of a class inside of an expression. operator int()
{return nI;} the conversion function is a method of a class
like: class a {
public:
int b;
operator int(){return(b+1);}
};
we would use this like so:
void main()
{
a aObject;
aObject.b=6;
printf(%i,aObject); //should print 7
}
It is possible to create conversion functions for converting to
different types. Each conversion function will be invoked
automatically depending on the type of each expression.