C++ -- In which case the compiler can deduce the type
<pre><code>vector&lt;Widget*&gt; vwp;

// populate vwp;

// Do need to specify the TYPE 'Widget'
for_each(vwp.begin(), vwp.end(), DeleteObject&lt;Widget&gt;()); // case I

template&lt;typename T&gt;
struct DeleteObject: public unary_function&lt;const T*, void&gt; {
    void operator() (const T* ptr) const
    {
      delete ptr;
    }
};

///////////////////////////////////////////////////////////

struct DeleteObjectB {
    template&lt;typename T&gt;
    void operator() (const T* ptr) const
    {
      delete ptr;
    }
};

vector&lt;Widget*&gt; vwpB;

// populate vwpB;

// Do not need to specify the TYPE 'Widget'
for_each(vwpB.begin(), vwpB.end(), DeleteObjectB()); // case II
</code></pre>

<p>My question is as follows:</p>

<pre><code>In case I, we need to specify the type.
In case II, we don't need to specify the type.
Is there a general rule that I can follow?
</code></pre>

<p>Thank you</p>
