How do I define my own namespace?

Discussion in 'C++' started by JustSomeGuy, Jul 7, 2004.

  1. JustSomeGuy

    JustSomeGuy Guest

    I am writing classes and I want them to belong to mynamespace

    What is the syntax to say that the class I'm defining is a member of
    mynamespace?
    What is the scope of the syntax and how does one go back to the previous
    namespace definition?


    TIA..
     
    JustSomeGuy, Jul 7, 2004
    #1
    1. Advertising

  2. JustSomeGuy

    Mike Wahler Guest

    "JustSomeGuy" <> wrote in message
    news:9uLGc.973055$Pk3.19837@pd7tw1no...
    > I am writing classes and I want them to belong to mynamespace
    >
    > What is the syntax to say that the class I'm defining is a member of
    > mynamespace?


    namespace mynamespace
    {
    class MyClass
    {
    };
    }

    > What is the scope of the syntax


    Syntax doesn't have scope. A namespace defines a scope.

    >and how does one go back to the previous
    > namespace definition?


    For definitions and declarations, just 're-open' it, e.g.

    namespace mynamespace
    {
    /* declarations and definitions */

    int i;
    /* etc */

    }

    /* other stuff */

    namespace mynamespace
    {
    /* more declarations and definitions */
    }

    /* more other stuff */

    For referring to entities within a namespace that is
    not the current scope, use the scope resolution operator:

    namespace xyz
    {
    ::mynamespace::i = 42;
    }


    Which C++ books are you reading?

    -Mike
     
    Mike Wahler, Jul 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    784
  2. Saverio M.
    Replies:
    0
    Views:
    535
    Saverio M.
    Jul 3, 2006
  3. Ben
    Replies:
    10
    Views:
    571
    Christopher Benson-Manica
    Oct 28, 2006
  4. Peng Yu
    Replies:
    0
    Views:
    653
    Peng Yu
    Sep 14, 2008
  5. David Filmer
    Replies:
    17
    Views:
    276
    J. Romano
    Aug 18, 2004
Loading...

Share This Page