Can someone explain NameSpace

This is a discussion on Can someone explain NameSpace within the C++ Programming forums, part of the General Programming Boards category; Can Someone explain to me in detail what namespace is?...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    24

    Can someone explain NameSpace

    Can Someone explain to me in detail what namespace is?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378
    ex. namespace [identifier] { namespace-body }

    A namespace declaration identifies and assigns a name to a declarative region.

    The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.

    The declarative region of a namespace declaration is its namespace-body.

    I hope this helps some!

  4. #4
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    I presume you are wondering why people include the line:

    using namespace std;

    In simple terms, use it to avoid name collisions. Basically when you are dealing with many header files some may contain variable names that conflic with other variable names. It is difficult to keep track of all these variables. Including this creates a separate namespace area for variable names.

  5. #5
    Shadow12345
    Guest
    #include <iostream>
    using namespace std;
    namespace cheese {
    int x = 5;
    };

    namespace Poop {
    int x = cheese::x * 2;
    }

    int main(void) {
    int x = Poop::x + 5;
    cout << "X is " << x << endl;

    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. namespace and class..help!
    By Joelito in forum C++ Programming
    Replies: 3
    Last Post: 01-05-2007, 09:38 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. where is standard namespace?
    By Mark S. in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2006, 06:30 AM
  4. variable size of namespace?
    By Dash_Riprock in forum C++ Programming
    Replies: 7
    Last Post: 08-11-2006, 07:57 PM
  5. Can someone explain "extern" to me?
    By valar_king in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 12:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21