
15 Jun
2009
15 Jun
'09
7:41 p.m.
Stewart, Robert wrote:
Why not make it even simpler and more general.
template <typename T> T null() {return T(); }
int main() { func(NULL); func(null<char*>()); ^^^^^
Presumably, you meant for null() to return T *. However, that doesn't address the overloading ambiguities that can result when overloading on int and char *, for example. That's why a new type is needed.
No, T is char* in my example. I meant the code to do exactly what I wrote. This does address the problem of pointer type overloading since you specify the pointer type and it returns the null value of that pointer type. Regards, luke