Yes, you added an implicit conversion to T* , so the compiler will use it to compare with NULL.
A few other notes:
NULL is an abbreviation of 0, so that means a comparison with 0 is allowed. (However, this does not apply to other integer values. 0 is special.)
Your type can also be implicitly used in boolean contexts. That is, it is legal:
Test test; if (test) { // ... }
C ++ 0x allows you to specify the explicit keyword for conversion statements to prevent such things.
Implicit conversion to pointer types is often quite dubious. In addition to conversion errors that occur in unexpected cases, it can resolve dangerous situations if the object owns the returned pointer. For example, consider a string class that allows implicit conversion to const char* :
BadString ReturnAString(); int main() { const char* s = ReturnAString();
source share