I am trying to understand namespaces in C++. I read that there are two ways of accessing namespace variables and functions. First one is to write using ::
and second one is by using using
directive at the top and not writing it again and again. I realized that the first method is better as the second one may lead to conflicts.
But, I want to know how actually 2nd method is working. For Example, If I write using namespace std
at the top, how does the compiler know for which functions it has to add std::
in the beginning and for which ones it has no to. If I have written a function in main, firstly it will check in my main file for the function and then it will check in the header files ( that I have declared at top of main file) for the function declaration. Now, according to my understanding the functions in std are declared inside namespaces. So, I will not find it if I search without using ::
.
So, when will std::
will get add at the beginning of a function?