Why am I able to use the names in the std namespace even though I’m "using namespace std;"?

  c++, namespaces, std

Isn’t there already a max function in the algorithm header file?
And by using namespace std;, I’m importing the function to the global namespace (which takes to arguments, and in this case both would be integers, so it shouldn’t be an overload).

So why isn’t there any naming conflict?

#include <iostream>
#include <algorithm>

using namespace std;

int max(int a, int b)
{
    return (a > b) ? a : b;
}

int main()
{
    cout << max(5, 10) << endl;
}

Source: Windows Questions C++

LEAVE A COMMENT