I used the find and replace to change all my cout, cin, string into std::cout, etc… yet I forgot to do so for the getline function. It still compiled even after I removed the std namespace.
What’s the deal?
I used the find and replace to change all my cout, cin, string into std::cout, etc… yet I forgot to do so for the getline function. It still compiled even after I removed the std namespace.
What’s the deal?
Very good question!
Yes, getline()
is part of std
. This happens in C++ because of something known as Argument-Dependent-Lookup (or ADL - also known as Koeing).
In short, once it doesn’t find the unqualified getline()
the compiler will look at the namespaces of the arguments used - in this case std::cin
and std::string
. Since both of these arguments are in the std
namespace, it looks there.
I encourage you to read the link above.
Ahh so it’s a smart way for the compiler to find functions by looking at what namespace its arguments are part of and searching there.
Thanks!