Advertisement

STD

Started by March 20, 2002 06:33 PM
12 comments, last by Cire 22 years, 9 months ago
quote: Original post by navigator
Isn''t it possible to get rid of ''std::'' everywhere by using the ''using namespace std'' declaration in the code?


That''s exactly what everyone''s said.

"I''ve learned something today: It doesn''t matter if you''re white, or if you''re black...the only color that really matters is green"
-Peter Griffin
"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that really matters is green"-Peter Griffin
quote: Original post by navigator
Isn''t it possible to get rid of ''std::'' everywhere by using the ''using namespace std'' declaration in the code?

Yes, but it''s a bad idea.

The objective of namespaces was to componentize functions and prevent function names, etc from clashing. If you blindly import the entire namespace with the using directive, then you''ve negated all the advantages of namespaces.

You can use the using directive at any scope - inside functions, etc, so you can minimize the level of namespace collisions. And since it''s resolved at compile time, it has no performance drawbacks.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
Advertisement
an example would be g++''s stl, for 2.96 (i don''t know about 3.x), there is some macro trickery going on that allows you to get away without stating std::, but generally it''s highly recommended you do, plus with some ide''s it will show youa a drop down panel of all objects within the namespace (which is mighty handy to say the least).
You do not need to do using namespace std, if you want to not put std:: in front of everything, do this:

take cout for example:

using std::cout

or if you want to use cin without std::

using std::cin


_____________________________________________________

ICQ #: 149510932

Google - OpenGL - DirectX - Windows Guide Network - MSDN - Symantec Virus Info

"Imagination is more important than knowledge." - Albert Einstein

This topic is closed to new replies.

Advertisement