title: ambiguous call in template error
body: <p>Can anyone tell me the cause of error ?</p>
  
  <p>Error is </p>
  
  <pre><code>C:\web\template1.cpp||In function 'int main()':|
  C:\web\template1.cpp|23|error: call of overloaded 'swap(int&amp;, int&amp;)' is ambiguous|
  C:\web\template1.cpp|6|note: candidates are: void swap(X&amp;, X&amp;) [with X = int]|
  c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&amp;, _Tp&amp;) [with _Tp = int]|
  C:\web\template1.cpp|24|error: call of overloaded 'swap(double&amp;, double&amp;)' is ambiguous|
  C:\web\template1.cpp|6|note: candidates are: void swap(X&amp;, X&amp;) [with X = double]|
  c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&amp;, _Tp&amp;) [with _Tp = double]|
  C:\web\template1.cpp|25|error: call of overloaded 'swap(char&amp;, char&amp;)' is ambiguous|
  C:\web\template1.cpp|6|note: candidates are: void swap(X&amp;, X&amp;) [with X = char]|
  c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&amp;, _Tp&amp;) [with _Tp = char]|
  ||=== Build finished: 3 errors, 0 warnings ===|
  </code></pre>
  
  <hr>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  template &lt;typename X&gt;
  void swap(X &amp;a, X &amp;b)
  {
      X temp = a;
      a = b;
      b = temp;
  }
  
  int main()
  {
      int i=10, j=20;
      double x=10.1, y=23.3;
      char a='x', b='z';
  
      cout&lt;&lt;"i="&lt;&lt;i&lt;&lt;"\tj="&lt;&lt;j&lt;&lt;endl;
      cout&lt;&lt;"x="&lt;&lt;x&lt;&lt;"\ty="&lt;&lt;y&lt;&lt;endl;
      cout&lt;&lt;"a="&lt;&lt;a&lt;&lt;"\tb="&lt;&lt;b&lt;&lt;endl;
  
      swap(i,j);
      swap(x,y);
      swap(a,b);
  
      cout&lt;&lt;"i="&lt;&lt;i&lt;&lt;"\tj="&lt;&lt;j&lt;&lt;endl;
      cout&lt;&lt;"x="&lt;&lt;x&lt;&lt;"\ty="&lt;&lt;y&lt;&lt;endl;
      cout&lt;&lt;"a="&lt;&lt;a&lt;&lt;"\tb="&lt;&lt;b&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>