Everything in the C++ standard library is in the std namespace.
A namespace will allow you to #include your own, or 3rd party headers and ensure that you have no conflicts. Example, if you make your own function: sin(x) and then someone uses your header and the <cmath> header at the same time, they'll have a conflict. If you put your sin(x) in a namespace, then they can specify which version of sin(x) they want to use.
They can specify the one in cmath with std::sin(x), or they can specify your version with yourNamespace::sin(x). The 'problem' is that you need to prepend std:: to everything you use from the standard library which is verbose and can make things harder to read for beginners.
Now if you aren't using any other libraries and don't have too many functions in your own source file, then you can tell the compiler, "just take everything from std::". To do that, we use the command usingnamespace std;
In human language, this says: take C's double ::sin(double) into the std namespace, and then define all the other versions of sin() that C++ has in <cmath>(float sin(float), longdouble sin(longdouble), double sin(int), double sin(long), etc)
Topic archived. No new replies allowed.
You are using a version without Ads of this website. Please, consider donating: