Archived

This topic is now archived and is closed to further replies.

Cire

STD

Recommended Posts

Null and Void    1088
Somehow you must specify the namespace (using namespace std, using std::whatver, or std::whatever) or you''re not using standard C++. When asking a question about standard C++ you shouldn''t bring up the compiler.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Like the way you put your functions into ''cateogories'' by putting them into classes and files into folders, namespaces are just a way of putting related code into categories. The C++ standard dictates that all standard library code must be placed into the std namespace. It does have its advantages.

It is easier to see by looking at your code how things relate (e.g. that''s in the sound namespace so it must be part of sound effects library), and it also stops name clashes developing (e.g. you can have two functions with the same name in different namespaces).

Imagine a C graphics library called ABC that has a functions called things like ABC_Flip. The ABC_ prefix would be used on all functions because here the Flip identifier is perhaps too short to avoid clashes when others use it in their code. Namespaces help get rid of this kind of pollution of your identifier names.

Try not to look on them as a pointless feature that gets in the way; it can make your code nicer.

Share this post


Link to post
Share on other sites
SabreMan    504
It''s worth noting that MS''s iostream.h header does not place its contents into namespace std. Some people seem to think that is the only difference between iostream and iostream.h. It''s not.

Share this post


Link to post
Share on other sites
BeerNutts    4400
I didn''t know a compiler could get an STD. Well, no wonder mines been acting so strange; it must have gotten syphilis!!

(I know, that''s an 8th grader joke, but when I saw STD, I thought, "Sexually Transmitted Disease

Share this post


Link to post
Share on other sites
merlin9x9    174
Well, yeah, especially from the capitalization. He probably whines about C++''s case sensitivity since he can''t manage just to copy something as simple as 3 letters verbatim.

Share this post


Link to post
Share on other sites
navigator    122
Isn''t it possible to get rid of ''std::'' everywhere by using the ''using namespace std'' declaration in the code?

Have a nice day,


---
Never trust a Troglotroll.

Share this post


Link to post
Share on other sites
matrix2113    122
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

Share this post


Link to post
Share on other sites
Oluseyi    2103
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!

Share this post


Link to post
Share on other sites
abdulla    164
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).

Share this post


Link to post
Share on other sites
Programmer One    746
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

Share this post


Link to post
Share on other sites