C++ smart pointer class #include &lt;iostream&gt;

template &lt;typename T&gt;
class my_smart_ptr {
    T* raw;
    unsigned * p_count;
public:
    my_smart_ptr(T* t):
    raw(t),
    p_count (new unsigned(1))
    {

    }

    my_smart_ptr(const my_smart_ptr&lt;T&gt; &amp; p):
    raw(p.raw),
    p_count(p.p_count)
    {
        ++(*p_count);
    }

    const my_smart_ptr&lt;T&gt; &amp; operator=(const my_smart_ptr&lt;T&gt;&amp; p)
    {
        if (p == *this)
        {
            return *this;
        }

        raw = p.raw;
        --(*p_count);
        ++(*(p.p_count));
        return *this;

    }

    ~my_smart_ptr()
    {
        --(*p_count);
        if (*(p_count) == 0)
        {
            delete raw;
        }
    }
};


class A{
public:

    A()
    {
        std::cout&lt;&lt; "A()" &lt;&lt; std::endl;
    }

    ~A()
    {
        std::cout&lt;&lt; "~A()" &lt;&lt; std::endl;
    }

};
int main()
{
    my_smart_ptr&lt;A&gt; a (new A);
    return 0;
}
I suppose that your class is trying to simulate a shared_ptr, however, I'm missing the part of overloading the dereference methods * and ->, because without them, your class seems useless (I can't do much with the pointed object).