A
Aries Sun
I am reading the book "Effective C++" Item 25 mentioned the following
code:
// a first cut at a class yielding NULL pointer objects
class NullClass {
public:
template<class T> // generates
operator T*() const { return 0; } // operator T* for
}; // all types T; each
// function returns
// the null pointer
const NullClass NULL; // NULL is an object of
// type NullClass
void f(int x); // same as we originally had
void f(string *p); // ditto
f(NULL); // fine, converts NULL to
// string*, then calls f(string*)
I have a hard time to understand the above, can anybody explain it to
me? thanks,
code:
// a first cut at a class yielding NULL pointer objects
class NullClass {
public:
template<class T> // generates
operator T*() const { return 0; } // operator T* for
}; // all types T; each
// function returns
// the null pointer
const NullClass NULL; // NULL is an object of
// type NullClass
void f(int x); // same as we originally had
void f(string *p); // ditto
f(NULL); // fine, converts NULL to
// string*, then calls f(string*)
I have a hard time to understand the above, can anybody explain it to
me? thanks,