c++ - Why can I call getline without using std::getline? -
i following c++ primer book , trying out code examples. intrigued one:
#include <iostream> #include <string> using std::string; using std::cin; using std::cout; using std::endl; int main() { string line; while (getline(cin,line)) cout << line << endl; return 0; }
before compiling code guessing compilation fail, since not using
while (std::getline(cin,line))
why getline in global namespace? understand, should happen if used
namespace std;
or
using std::getline;
i using g++ version 4.8.2 on linux mint debian edition.
this argument dependent lookup.
unqualified lookup (what doing when call getline()
instead of std::getline()
) start trying normal name lookup getline
. find nothing - have no variables, functions, classes, etc. in scope name.
we in "associated namespaces" of each of arguments. in case, arguments cin
, line
, have types std::istream
, std::string
respectively, associated namespaces both std
. redo lookup within namespace std
getline
, find std::getline
.
there many more details, encourage read reference cited. process additionally known koenig lookup.
Comments
Post a Comment