| | |
About the namespaces
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
Originally Posted by vivekgalatage
can anyone please explain me about the concept of namespaces?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
General idea:
You know how you can enclose something inside braces and it is only visible inside the braces? Like:
That's called a variable's 'scope'
Well, namespaces allow you to NAME a scope, like this:
Think of them as 'named globals', almost as if they belonged to a struct. But a namespace is not a description of things (like a struct would be), it is an implementation of things. That is, the Chainsaw::i was declared as a variable inside the namespace just as if it were a global variable.
You know how you can enclose something inside braces and it is only visible inside the braces? Like:
C++ Syntax (Toggle Plain Text)
{ int i; // visible only inside the braces } i = i + 1; // i isn't seen, or isn't the one in the braces.
That's called a variable's 'scope'
Well, namespaces allow you to NAME a scope, like this:
C++ Syntax (Toggle Plain Text)
namespace Chainsaw { int i; }; { int i; i = 0; // this is the 'i' declared inside THIS scope Chainsaw::i = 0; // this is the 'i' declared inside the Chainsaw name space scope }
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by vivekgalatage
Hello Everyone
can anyone please explain me about the concept of namespaces?
Regards
std is a namespace, and std::cout, refers to the object in std called cout.
So you can define an object called cout, without breaking the one definition rule. For example: In a large program, many programmers work together, and the possebility for several programmer have defined object with the same name, is huge. So if every programmer(or a programmer group) have defines a namespace, it doesn`t matter if several programmers have define the same name on several object`s as long as it`s in a namespace.
Edit: oops, I didn`t see the other threads.
![]() |
Similar Threads
- adding namespaces to XmlSerializer when deserializing (C#) (XML, XSLT and XPATH)
- Namespaces (C#)
- Ignoring xmlns namespaces in the input xml file (XML, XSLT and XPATH)
Other Threads in the C++ Forum
- Previous Thread: every thing is object?
- Next Thread: Arrays
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






