Why don't you use using namespace std?

Asked 1 years ago, Updated 1 years ago, 66 views

Why don't you write using namespace std;? Like std::out, std::cin, std::cin, I don't know why. Is it inefficient? Or is it because the variables are at risk of blurring? Does it affect the performance of the program if the application gets bigger?

c++ namespace std

2022-09-21 19:33

1 Answers

It has nothing to do with performance, but it has to do with conflict. Think of the following:

There are two libraries A and B. Let's say A has only func1() and B has only func2(). Since there are no overlapping functions, in this case, using namespace foo; using namespace bar; You can use . It's going to work.

But if one day foo is upgraded and func2() is added, using namespace foo; using namespace bar; In , a collision is caused by func2(). therefore foo::func2() bar::func2() in conjunction with If you specify namespace, there will be no conflict Using namespace... is not recommended.


2022-09-21 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.