no match for ‘operator=’ error with g++ <p>I have a class AP</p> <pre><code>template&lt;typename T&gt; class AP : public std::auto_ptr&lt;T&gt; { typedef std::auto_ptr&lt;T&gt; Super; public: AP() : Super() { } AP(T* t) : Super(t) { } AP(AP&lt;T&gt;&amp; o) : Super(o) { } }; </code></pre> <p>And a function to return it. </p> <pre><code>namespace AIR { namespace Tests { namespace { AP&lt;A&gt; CreateGraph() { AP&lt;A&gt; top(A::Create("xyz").release()); ... return top; } AP&lt;A&gt; top; top = CreateGraph(); </code></pre> <p>When I compile the code</p> <pre><code>AP&lt;A&gt; top; top = CreateGraph(); </code></pre> <p>I got this error message </p> <pre><code>no match for ‘operator=’ in ‘top = AIR::Tests::&lt;unnamed&gt;::CreateGraph()()’ </code></pre> <p>I added this operator to the AP class, but it doesn't work. </p> <pre><code>AP&lt;T&gt;&amp; operator=(AP&lt;T&gt;&amp; o) { (*(Super*)this) = o; return *this; } </code></pre> <p>What's wrong with the class?</p> <h2>EDIT</h2> <p><code>top.reset(CreateGraph().release())</code> solved this issue.</p>