min is a standard library template function. Removing const from the parameters will change the function sufficiently to act as an overload and remove ambiguity, but you can have problems with temporary values and it still doesn't address the problem of invading the implementation's namespace. How about, instead of asking for every standard name under the sun with
Code:
using namespace std;
You instead just ask for what you use:
Code:
#include <iostream>
using std::cout;
template<class T>
T min(T &a, T &b){
if (a < b)
return a;
else
return b;
}
int main() {
int a(0),b(2);
cout << min(a,b);
return 0;
}
Solving this problem is, after all, the whole purpose of namespaces. Or you could just use std::min:
Code:
#include <iostream>
using std::cout;
using std::min;
int main() {
int a(0),b(2);
cout << min(a,b);
return 0;
}