what does the operator string() { some code } do?
It is an automatic type conversion operator. This class you are talking about can be implicitly converted to a string. This link might help you with a few more examples.
operator Type() { ... }
is the (implicit) conversion operator. For example, if class Animal
implements operator string()
, then the code
Animal a;
...
do_something_with ( (string)a );
will become something like
do_something_with ( (Animal::operator string)(&a) );
See http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr385.htm for some more examples.
If just returns a string represantation of your current object, e.g. for printing it on the console.
It's overloading the conversion operator. A class which has the function
operator string();
defined can be converted to a string.