I was just reading a little bit on them from http://www.cplusplus.com/doc/tutorial/namespaces/
and it seems like a struct is capable of the same things? Or even a class for that matter. Maybe someone here can better define what a namespace is, and how it differs from a struct/class?
I was just reading a little bit on them from http://www.cplusplus.com/doc/tutorial/namespaces/ and it seems
Share
Namespaces and class-types are not capable of the same things. Namespaces are mainly used to group types and functions together to avoid name collisions, while class-types hold data and operations that work on that data.
To just group functions and objects by using a class-types you’d have to make them static:
Without
staticyou’d have to create instances of the class-types to use them. A namespace is much better suited here:Another important thing are
usingdeclarations and directives:With class-types there simply is no mechanism that allows that.
What class-types give you over namespaces is that you can have multiple instances with differing state – if you need that use a class-type.