K
K
kingslayer2021-10-13 19:49:51
C++ / C#
kingslayer, 2021-10-13 19:49:51

Why is it giving errors?

template <typename T>
void swap(T & a, T & b);

int main()
{
  int a = 10;
  int b = 12;
  swap(a, b);
  return 0;
}

template <typename T>
void swap(T & a, T & b)
{
  T temp;
  temp = a;
  a = b;
  b = temp;
}


14 11 C:\Users\A-technics\Desktop\main.cpp [Error] call of overloaded 'swap(int&, int&)' is ambiguous
14 11 C:\Users\A-technics\Desktop\main.cpp [Note ] candidates are:
8 6 C:\Users\A-technics\Desktop\main.cpp [Note] void swap(T&, T&) [with T = int]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question