<p>Below are lines from "the c++ programming language"</p>

<pre><code>template&lt;class T &gt; T sqrt(T );
template&lt;class T &gt; complex&lt;T&gt; sqrt(complex&lt;T&gt;);
double sqrt(double);
void f(complex&lt;double&gt; z )
{
s q r t (2 ); // sqrt&lt;int&gt;(int)
sqrt(2.0) ; // sqrt(double)
sqrt(z) ; // sqrt&lt;double&gt;(complex&lt;double&gt;)
}
</code></pre>

<p>I dont understand why sqrt(z) ; calls <code>sqrt&lt;double&gt;(complex&lt;double&gt;)</code> can any body please explain.</p>

<p>Author says, 
<code>T sqrt&lt;complex&lt;T&gt;&gt;</code>  is more specialized than <code>T sqrt &lt;T&gt;</code> but there is a seperate declaration for <code>template&lt;class T &gt; complex&lt;T&gt; sqrt(complex&lt;T&gt;);</code> why not use that?</p>

Well, the function used is the one you are talking about
```
sqrt<double>(complex<double>)
```
is an instance of the template
```
template <class T> complex<T> sqrt(complex<T>)
```
.
Your misunderstanding was in the signification of the template instance and not in the overloading process.