This is a type conversion operator. It defines an implicit conversion between an instance of the class and the specified type (here T* ). Its implicit return type is, of course, the same.
Here, the NullClass instance, when requested to convert to any type of pointer, will lead to an implicit conversion from 0 to the specified type, i.e. null pointer for this type.
On the side of the note, conversion operators can be made explicit:
template<class T> explicit operator T*() const {return 0;}
This avoids implicit conversions (which can be a subtle source of errors), but allows the use of static_cast .
Quentin
source share