Basic C++ object class I have implemented a basic object class in C++, and I want to make sure that I have implemented everything efficiently and safely, as I made a few mistakes while making it, which I corrected, but I could have left a few more mistakes behind:

class object
{
private:
    class dummy
    {
    public:
        dummy()
        {
        }
        virtual ~dummy()
        {
        }
        virtual const std::type_info &amp;type() = 0;
        virtual dummy *duplicate() const = 0;
        virtual bool eq(object &amp;) = 0;
    };

    template &lt; typename _Ty &gt; class data : public dummy
    {
    public:
        data()
        {
        }

        data(const _Ty &amp;_Value)
            : __data(_Value)
        {
        }

        ~data()
        {
        }

        const std::type_info &amp;type()
        {
            return typeid(_Ty);
        }

        data *duplicate() const
        {
            return new data&lt;_Ty&gt;(__data);
        }

        bool eq(object &amp;_Obj)
        {
            return _Obj.cast&lt;_Ty&gt;() == __data;
        }

        _Ty __data;
    };

    dummy *d;
public:
    object()
    {
    }

    template &lt; typename _Ty &gt; object(const _Ty &amp;_Value)
        : d(new data&lt;_Ty&gt;(_Value))
    {
    }

    object(const object &amp;_Obj)
        : d(_Obj.d-&gt;duplicate())
    {
    }

    ~object()
    {
        if (!empty())
        {
            delete d;
        }
    }

    const std::type_info &amp;type()
    {
        return (empty() ? typeid(void) : d-&gt;type());
    }

    object &amp;operator=(object &amp;_Rhs)
    {
        d = _Rhs.d-&gt;duplicate();
        return *this;
    }

    object &amp;swap(object &amp;_Rhs)
    {
        std::swap(*this, _Rhs);
        return *this;
    }

    template &lt; typename _Ty &gt; object &amp;operator=(const _Ty &amp;_Value)
    {
        d = new data&lt;_Ty&gt;(_Value);
        return *this;
    }

    template &lt; typename _Ty &gt; _Ty cast()
    {
        if (type() == typeid(_Ty))
        {
            return static_cast&lt;data&lt;_Ty&gt; *&gt;(d)-&gt;__data;
        }
        throw std::exception("Invalid cast type");
    }

    bool operator==(object &amp;_Rhs)
    {
        return (type() == _Rhs.d-&gt;type() ? d-&gt;eq(_Rhs) : false);
    }

    template &lt; typename _Ty &gt; bool operator==(_Ty _Value)
    {
        return (type() == typeid(_Ty) ? cast&lt;_Ty&gt;() == _Value : false);
    }

    bool operator!=(object &amp;_Rhs)
    {
        return !(*this == _Rhs);
    }

    template &lt; typename _Ty &gt; bool operator!=(const _Ty &amp;_Value)
    {
        return !(*this == _Value);
    }

    bool empty()
    {
        return !d;
    }
};
As per common naming convention, the class names should start with a capital letter.
It may be more readable to put the template line above the class line:

template &lt; typename _Ty &gt;
class data : public dummy
{
}

Your bool functions should be const.  Any member function that doesn't modify data members should be const.  Such functions also include accessors ("getters") and the bool operators (operator==, operator!=, operator&lt;, and operator&gt;).

For instance, with empty():

bool empty() const
{
    // ...
}


and operator==:

bool operator==(object &amp;_Rhs) const
{
    // ...
}


Also, the above parameter should be const&amp; since _Rhs is not being modified.
If you're not defining your own constructor and/or destructor, you don't need to make them yourself.  The compiler will make them for you.

However, if you're using C++11, you can have an explicitly defaulted constructor and destructor:

data() = default;
~data() = default;