Agree that using namespace XXX
is not a good practice. However, prefixing namespaces::
in each and every call is not only tedious but sometimes irritating too. for example, look at the code below which is using standard namespace std
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
However, I can get rid of repeating std::
by just importing the function itself via using
keyword as
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Is there any specific reason why I shouldn't do this rather than prefixing std:: in all the statements. if there is no specific reason, why this approach is not promoted as against prefixing std::
?
I understand from C++ specification that using std::func
will also import overloaded definition.