In my C++ code I don't use the declarations using namespace std;
or using namespace boost;
. This makes my code longer and means more typing. I was thinking about starting to use the "using" declarations, but I remember some people arguing against that. What is the recommended practice? std and boost are so common there should be no much harm in that?
I use using namespace
only in C++ files, not in headers. Besides, using hole namespace not needed in most of times. For instance, you could write using boost::shared_ptr
or using std::tr1::shared_ptr
to easily switch between shared_ptr
implementations.
Sample:
#include <iostream>
using std::cout;
int main()
{
cout << "test" << std::endl;
return 0;
}
Using namespace ...
was not invented just for fun.
If you have a good reason to use it, then do so (and the frequent use of stuff from these namespaces is the exact good reason). Don't listen to fanatics who tell you everything they don't want to do for obscure reasons themselves is evil.
However, a good source for reasoning in these regards is C++ FAQ lite: http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
I have read it and still decided to use it like you want to. Now you can make your own informed decision :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With