Regarding your Question
operator type ()
is a so-called cast operator. if there is a need for conversion to type
, then that operator function is used to do the conversion.
in your example, cout uses your operator T* ()
to convert your x1 object using a user defined implicit conversion to a pointer, which is then output by ostream's (cout is of class std::ostream) operator<<
which takes a void* .
Other Problems
To help you figure out other problems, change the header file name from iostream.h
to iostream
. Standard C++ does not know iostream.h
. Those files were called like that before C++ was made a Standard. Also, all C headers you use, like math.h, stdio.h
are still valid in C++, but they are so-called backward-compatibility header files. You should include for example cmath
and cstdio
instead. That will put all names that are not macros in C into the namespace std
. Instead of using cout
, you use std::cout
. Likewise for other identifiers too.