Click to See Complete Forum and Search --> : Nested namespace


allangal
September 20th, 2002, 02:22 PM
I have not had a need to implement namespaces to our objects until lately. And I have not found any good example on how to do it in a nice looking way. Example:

namespace MySystem {
namespace MySubSystem {
namespace MySubSubSystem {
public __gc class MyClass{
...
...
};
};
};
};


What a nasty indentations, etc...

Here's what I found will work.

file stdafx.h

namespace MySystem{};
namespace MySystem{ namespace MySubSystem {} };
namespace MySystem{ namespace MySubSystem { namespace MySubsubSystem {} } };

namespace MySubSystem = MySystem::MySubSystem;
namespace MySubSubSystem = MySystem::MySubSystem::MySubSubSystem;


In class MyClass header file.

namespace MySubSubSystem {
public __gc class MyClass {
...
...
};
};

Isn't it a nice good looking way?

Keep programming!

Andreas Masur
September 20th, 2002, 03:11 PM
Originally posted by allangal
Here's what I found will work.

file stdafx.h

namespace MySystem{};
namespace MySystem{ namespace MySubSystem {} };
namespace MySystem{ namespace MySubSystem { namespace MySubsubSystem {} } };

namespace MySubSystem = MySystem::MySubSystem;
namespace MySubSubSystem = MySystem::MySubSystem::MySubSubSystem;

Isn't it a nice good looking way?
Hmmm...I do not want to offense you but this is basically one standard way to work and map namespaces and it's called 'aliasing'. I am not sure why you posted this to the .NET forum...but it is not only limited to .NET... :cool:

Nevertheless if you did not know this before than I would say: Congratulations...it is always a nice feeling to find out new things on your own...

allangal
September 20th, 2002, 05:47 PM
Mr. Masur,

One of the reasons that this forum is here is for us to express our thoughts about things in the forum. I posted it so, that others may see and show better suggestions than what I showed. Your comment does not do any help, nor does impress me. If you really wanna show your guts, try certification exams, and if you get a perfect score, then you'll impress me.

proxima centaur
September 20th, 2002, 06:15 PM
I do not see any bad feelings in Andreas comment nor do I understand why you are offended.

I agree this does not belong in this forum, but rather in C++ non VC related as it applies to C++ in general.

I did not know of the namespace aliasing before this post and in that sense, it was very helpful to me.

But. And this might be an implementation of the compilor issue, please note that the namespace alias is "read-only". Therefore, you can't use the alias to insert new classes in the namespace. You have to use the "real" namespace identifier. This is what I got from trying this in VC++6. I don't know whether this is supposed to be that way or not. Anybody knows?

Thanks!