Custom nullptr_t class I tried to write a nullptr_t class based on the official proposal to be used in C++03 only. The only differences with the proposal are that we can compare two nullptr_t instances and that it is convertible to bool via an overload to void* to avoid unwanted behaviour such as int a = nullptr; for example. Here is the class:

const class nullptr_t
{
    public:

        // Return 0 for any class pointer
        template&lt;typename T&gt;
        operator T*() const
        {
            return 0;
        }

        // Return 0 for any member pointer
        template&lt;typename T, typename U&gt;
        operator T U::*() const
        {
            return 0;
        }

        // Used for bool conversion
        operator void*() const
        {
            return 0;
        }

        // Comparisons with nullptr
        bool operator==(const nullptr_t&amp;) const
        {
            return true;
        }
        bool operator!=(const nullptr_t&amp;) const
        {
            return false;
        }

    private:

        // Not allowed to get the address
        void operator&amp;() const;

} nullptr = {};


I would like to know if there is any actual flaw in this completed implementation or if there is a difference in the behaviour compared to the C++11 type std::nullptr_t besides the namespace that I can't see.
At the moment, your implementation allows

auto&amp; p = nullptr;


This is forbidden in C++11 as nullptr is an rvalue.  You also do not allow the following:

auto p = nullptr;
auto pp = &amp;p;


While C++11 does allow it.  You are also missing overloads for comparison operators.

A simple workaround would be to remove the operator&amp; overload and add a macro:

#define nullptr (nullptr_t())


Also, I'd generally use struct X { ... } const x; instead of const struct X { ... } x;.