ambiguous call for templatized function

  c++

🙂
I have a problem with creating a template in c++. I am an absolute beginner, so please be gentle on me…
I am using xcode for mac.
When passing an integer to a swap function I get the error code "ambiguous call". Passing the strings works fine.

this is my code

#include <iostream>
#include <cmath>
using namespace std;

template<typename T>

void swap(T &c, T &d)
{
T temp = c;
c = d;
d = temp;
}

int main()
{
int a = 10;
int b = 20;

swap(a, b);
cout << a << "t" << b;

string first_name = "Bob";
string last_name = "Hoskins";
swap(first_name, last_name);

cout << first_name << "t" << last_name;

return 0;
}

Many thanks for your help

Source: Windows Questions C++

LEAVE A COMMENT