954,148 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

About the namespaces

Hello Everyone


can anyone please explain me about the concept of namespaces?

Regards

vivekgalatage
Newbie Poster
6 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 
can anyone please explain me about the concept of namespaces?

Doing a search is your best bet for general queries.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

General idea:

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

{
    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:

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
}

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.

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

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.

TITAN
Newbie Poster
3 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You