0

Here's my code trying to simply add 2 numbers.

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

template<class first, class second>
first plus(first x, second y) {

    return x + y;
}
int main() {

    int a = 123;
    int b = 21;

    plus(a, b);

    return 0;
}

The plus() gives me an error stating that it's "ambiguous". This is basically copied code I've seen in tutorials(where it has worked!) on templates so I'm really confused now.

SS2
  • 1
  • 3

2 Answers2

2

Remove the using namespace std, you are colliding with std::plus

http://en.cppreference.com/w/cpp/utility/functional/plus

Curious
  • 20,870
  • 8
  • 61
  • 146
-2

I've solved the issue either removing std namespace or changing the function name is all it takes!

SS2
  • 1
  • 3