How come a pointer to a derived class cannot be passed to a function expecting a reference to a pointer to the base class?
<p>Sorry for the long title but I did want to be specific.
I expected the following code to work but it doesn't and I can't figure out why :/</p>

<pre><code>#include &lt;cstdio&gt;
#include &lt;cassert&gt;

class UniquePointer
{
public:
    void Dispose()
    {
        delete this;
    }

    friend void SafeDispose(UniquePointer*&amp; p)
    {
        if (p != NULL)
        {
            p-&gt;Dispose();
            p = NULL;
        }
    }
protected:
    UniquePointer() { }
    UniquePointer(const UniquePointer&amp;) { }
    virtual ~UniquePointer() { }
};

class Building : public UniquePointer
{
public:
    Building()
    : mType(0)
    {}
    void SetBuildingType(int type) { mType = type; }
    int GetBuildingType() const { return mType; }
protected:
    virtual ~Building() { }
    int mType;
};

void Foo()
{
    Building* b = new Building();
    b-&gt;SetBuildingType(5);
    int a = b-&gt;GetBuildingType();
    SafeDispose(b);     // error C2664: 'SafeDispose' : cannot convert parameter 1 from 'Building *' to 'UniquePointer *&amp;'
    b-&gt;Dispose();
}

int main(int argc, char* argv[])
{
    Foo();
    return 0;
}
</code></pre>
