943,832 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2218
  • C++ RSS
Aug 3rd, 2004
0

About the namespaces

Expand Post »
Hello Everyone


can anyone please explain me about the concept of namespaces?

Regards
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
vivekgalatage is offline Offline
6 posts
since Aug 2004
Aug 3rd, 2004
0

Re: About the namespaces

Quote originally posted by vivekgalatage ...
can anyone please explain me about the concept of namespaces?
Doing a search is your best bet for general queries.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Aug 3rd, 2004
0

Re: About the namespaces

General idea:

You know how you can enclose something inside braces and it is only visible inside the braces? Like:

C++ Syntax (Toggle Plain Text)
  1. {
  2. int i; // visible only inside the braces
  3. }
  4. 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)
  1. namespace Chainsaw
  2. {
  3. int i;
  4. };
  5.  
  6. {
  7. int i;
  8. i = 0; // this is the 'i' declared inside THIS scope
  9. Chainsaw::i = 0; // this is the 'i' declared inside the Chainsaw name space scope
  10. }
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.
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Aug 3rd, 2004
0

Re: About the namespaces

Quote originally posted by vivekgalatage ...
Hello Everyone


can anyone please explain me about the concept of namespaces?

Regards
I`ll try.
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TITAN is offline Offline
3 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: every thing is object?
Next Thread in C++ Forum Timeline: Arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC