By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

How do I define my own namespace?

P: n/a
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..
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"JustSomeGuy" <no**@nottelling.com> 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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.