In C++, when referencing identifiers declared in the standard namespace, these identifiers need to be qualified with "std::" (name of namespace + scope resolution operator). However, my program compiles without error even if I don't qualify identifiers of functions.
For instance, the following code compiles without error:
#include <iostream>
#include <string>
int main() {
std::string s;
std::getline(std::cin, s); // works.
getline(std::cin, s); // also works. Why?
}
Running g++ --version
outputs the following:
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Why is the second last line in the sample code above correct? Does it work for all compilers/environments?