C++ -- why we have to define this friend template class
<pre><code>template&lt;class T&gt;
class auto_ptr2 {
public:
    explicit auto_ptr2(T *p = 0): pointee(p) {}
    template&lt;class U&gt;
    auto_ptr2(auto_ptr2&lt;U&gt;&amp; rhs): pointee(rhs.release()) {}
    ~auto_ptr2() { delete pointee; }
    template&lt;class U&gt;
    auto_ptr2&lt;T&gt;&amp; operator=(auto_ptr2&lt;U&gt;&amp; rhs)
    {
        if (this != &amp;rhs) reset(rhs.release());
        return *this;
    }
    T&amp; operator*() const { return *pointee; }
    T* operator-&gt;() const { return pointee; }
    T* get() const { return pointee; }
    T* release()
    {
        T *oldPointee = pointee;
        pointee = 0;
        return oldPointee;
    }
    void reset(T *p = 0)
    {
        if (pointee != p) {
            delete pointee;
            pointee = p;
        }
    }
private:
    T *pointee;

    //template&lt;class U&gt; friend class auto_ptr2&lt;U&gt;;
        // Question 1&gt; Why we have to define this friend class
        // Question 2&gt; I cannot compile this code with above line with VS2010.
        // Error 1 error C3772: 'auto_ptr2&lt;T&gt;' : invalid friend template declaration
};
</code></pre>

<p>thank you</p>
