Wednesday, October 31, 2018

namespaces - C++ "using std::" vs calling std:: every time








Let's say I'm using #include in C++ and I'm making a print statement. I can choose either to:



using namespace std;
[...]
cout << "Hello" << endl;


or




using std::cout;
using std::endl;
[...]
cout << "Hello" << endl;


or



std::cout << "Hello" << std::endl;



I'm led to believe, and perhaps this is incorrect, that the first one is somewhat to be avoided, as it can add a lot of unnecessary bloat to your program. However, I don't know if there's any difference between the second and third styles in terms of performance. The majority of code that I see that uses libraries tends to use the third style; however for me if there's no tradeoff in using the second one, it seems like the cleanest and most readable method, especially if you're making a lot of calls to the functions or objects in question.



Can anyone enlighten me?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...