About the namespaces

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 6
Reputation: vivekgalatage is an unknown quantity at this point 
Solved Threads: 0
vivekgalatage vivekgalatage is offline Offline
Newbie Poster

About the namespaces

 
0
  #1
Aug 3rd, 2004
Hello Everyone


can anyone please explain me about the concept of namespaces?

Regards
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: About the namespaces

 
0
  #2
Aug 3rd, 2004
Originally Posted by vivekgalatage
can anyone please explain me about the concept of namespaces?
Doing a search is your best bet for general queries.
"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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: About the namespaces

 
0
  #3
Aug 3rd, 2004
General idea:

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

  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 3
Reputation: TITAN is an unknown quantity at this point 
Solved Threads: 0
TITAN TITAN is offline Offline
Newbie Poster

Re: About the namespaces

 
0
  #4
Aug 3rd, 2004
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC