Page 1 of 1

Namespaces

Posted: Sat Jan 31, 2009 12:55 pm
by Ginto8
What is the purpose of a namespace, and why use it? I know there's namespace std in the STL, and Nehe's new tutorials have a namespace nehe, but what do you actually use it for?

Re: Namespaces

Posted: Sat Jan 31, 2009 1:05 pm
by LeonBlade
A namespace is basically making things neat... it's a container if you will...
The namespace you are in is just a way to keep all your classes organized under something bigger.

Commands are in a function, functions are in classes, classes are in a namespace.

Re: Namespaces

Posted: Sat Jan 31, 2009 1:13 pm
by MarauderIIC
If you're working on a large project it prevents function/class name overlap, theoretically, too. I've never used one in a C++ project, although I use them in C# on separate modules with namespaces of "Appname.Business" (contains classes that do calculations on data), "Appname.Data" (contains classes that interface with database), "Appname.Utility" (contains secure redirect fn)...

Re: Namespaces

Posted: Sat Jan 31, 2009 3:00 pm
by BOMBERMAN
The namespace concept appears in order to control the scope of names to allow the same names to be used without conflicts - Text from the book "Programming in c++"

Re: Namespaces

Posted: Sat Jan 31, 2009 4:05 pm
by sparda
Namespaces are used to avoid name clashes between existing libraries, and anything you might write (in its most basic use).

I've seen it used in a modular programming paradigm as well.

Re: Namespaces

Posted: Sat Jan 31, 2009 8:52 pm
by Ginto8
BOMBERMAN wrote:The namespace concept appears in order to control the scope of names to allow the same names to be used without conflicts - Text from the book "Programming in c++"
I thought that might have been what it was... Thanks for clarifying. :)