We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr
.
Well, no need anymore for the nasty mac
When you have a function that can receive pointers to more than one type, calling it with NULL
is ambiguous. The way this is worked around now is very hacky by accepting an int and assuming it's NULL
.
template
class ptr {
T* p_;
public:
ptr(T* p) : p_(p) {}
template
ptr(U* u) : p_(dynamic_cast(u)) { }
// Without this ptr p(NULL) would be ambiguous
ptr(int null) : p_(NULL) { assert(null == NULL); }
};
In C++11
you would be able to overload on nullptr_t
so that ptr
would be a compile-time error rather than a run-time assert
.
ptr(std::nullptr_t) : p_(nullptr) { }