Thread: need help with namespace in c++

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Thumbs up need help with namespace in c++

    I am newbie to namespace usage in C++. Can anyone clarify me the below queries?

    Can one namespace be derived from another namespace?Can c++ namespace be derived from c++ class?Also can c++ class be derived from c++ namespace?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by leo2008
    Can one namespace be derived from another namespace?
    That depends on what you mean by "derive". It certainly cannot be derived in the same way that classes can, but you could say, make an alias for an existing namespace.

    Quote Originally Posted by leo2008
    Can c++ namespace be derived from c++ class?
    No.

    Quote Originally Posted by leo2008
    Also can c++ class be derived from c++ namespace?
    No.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    a namespace is a container. that is all. you cannot allocate memory for a namespace, because it does not represent storage. you cannot instantiate a namespace because it is not a type. it's simply a place to put things to keep them organized. let's say you have a program that links two libraries: one for communicating over a network connection, and another for communicating with the user via the console. let's say they both implement a function called ReadLine(). without namespaces, those two functions would conflict. but let's say we put the network library in a namespace called Network, and the console library in a namespace called Console. now you can call Console::GetLine() or Network::GetLine(), and they don't conflict. get it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using namespace ....
    By Lesshardtofind in forum C# Programming
    Replies: 3
    Last Post: 11-17-2012, 08:53 PM
  2. Friend of namespace or of namespace function?
    By Programmer_P in forum C++ Programming
    Replies: 18
    Last Post: 03-13-2011, 06:46 PM
  3. using namespace std?
    By Nathan1993 in forum C++ Programming
    Replies: 2
    Last Post: 08-22-2005, 09:33 AM
  4. Namespace
    By Hypercase in forum C++ Programming
    Replies: 2
    Last Post: 08-15-2005, 05:46 AM
  5. namespace std
    By blankstare77 in forum C++ Programming
    Replies: 27
    Last Post: 07-24-2005, 12:33 PM