STD
is using STD in front of cout or anything, absolutely necessary if i have microsoft visual c++ compiler?
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.
March 20, 2002 07:17 PM
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.
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.
quote: Original post by Cire
ive heard that you only need std with certain compilers
Not true. namespace std is defined by the C++ Standard. Any compiler that doesn''t support it is not worth using.
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
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.
fstream.h is even worse.
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
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
(I know, that''s an 8th grader joke, but when I saw STD, I thought, "Sexually Transmitted Disease
My Gamedev Journal: 2D Game Making, the Easy Way
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement