What is using namespace?

Asked

Viewed 1,877 times

7

Since the beginning of my C++ learning I have been told to use the namespace std, not to spend all the time using the std::cout.

But after studying more about language, I learned that :: is a target operator, but what about namespace, what his behaviors and influences are in the code?

1 answer

9


Is a language directive which determines that you will use a namespace in that code implicitly. This command really prevents you from giving the name of the namespace.

The namespace is one about name for types, functions and other possible members. It is a way to avoid equal names by making different things collide and. So whatever you use has to write the last name followed by :: and then the name of what you will use. This is just not necessary for what is in the namespace global.

Since most cases give no problem and cause no ambiguity you can avoid writing this last name on each call, you say that starting from that point in the code until the end of the scope you accept that that last name is already valid.

Some people say that it is not good to do this, but it is exaggeration. Read more about in Why is it not good practice to use namespace "Std" in C++?.

If you want to understand more about namespaces has about C#, the concept is identical.

You may be wondering if you couldn’t write alone using. Can’t because alone he does something else, it works like a alias for language types and other constructions or to specific statements.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.