Multi-level namespace, again.

C

Cat

In C#, this is legal
namespace MyNamespace.MyApp
{
class MyClass{}
}

I asked about this, and someone told me that
namespace MyNamespace::MyApp
{
ref class MyClass{};
}
is the correct syntax. But I tried that on Visual C++.NET 2008,
it didn't compile.
error C2653: 'MyNamespace' : is not a class or namespace name
Only the following worked.
namespace MyNamespace
{
namespace MyApp
{
ref class MyClass{};
}
}

but that makes me indent a lot of spaces if I would like to define
a namespace like MyCompany.MyDivision.MyProject.MyModule.
Is it impossible to define nice one line multilevel namespace like in
C#?
 
D

David Wilkinson

Cat said:
In C#, this is legal
namespace MyNamespace.MyApp
{
class MyClass{}
}

I asked about this, and someone told me that
namespace MyNamespace::MyApp
{
ref class MyClass{};
}
is the correct syntax. But I tried that on Visual C++.NET 2008,
it didn't compile.
error C2653: 'MyNamespace' : is not a class or namespace name
Only the following worked.
namespace MyNamespace
{
namespace MyApp
{
ref class MyClass{};
}
}

but that makes me indent a lot of spaces if I would like to define
a namespace like MyCompany.MyDivision.MyProject.MyModule.
Is it impossible to define nice one line multilevel namespace like in
C#?

Cat:

I always do it like this:

namespace MyNamespace { namespace MyApp {

ref class MyClass
{
};

}}

without any indentation.
 
C

Cat

Cat:

I always do it like this:

namespace MyNamespace { namespace MyApp {

ref class MyClass
{

};
}}

without any indentation.

Thank you. So, it is wrong something like
namespace A::B::C
{
.....
}
, right?
 
M

Mark Salsbery [MVP]

Cat said:
Thank you. So, it is wrong something like
namespace A::B::C
{
.....
}
, right?

Yes, that's wrong. Indentation, however, is up to you - the compiler
doesn't care :)

Mark
 
C

Cholo Lennon

Cat said:
In C#, this is legal
namespace MyNamespace.MyApp
{
class MyClass{}
}

I asked about this, and someone told me that
namespace MyNamespace::MyApp
{
ref class MyClass{};
}
is the correct syntax. But I tried that on Visual C++.NET 2008,
it didn't compile.
error C2653: 'MyNamespace' : is not a class or namespace name
Only the following worked.
namespace MyNamespace
{
namespace MyApp
{
ref class MyClass{};
}
}

but that makes me indent a lot of spaces if I would like to define
a namespace like MyCompany.MyDivision.MyProject.MyModule.
Is it impossible to define nice one line multilevel namespace like in
C#?

Some time ago there was a proposal to add this feature to C++ grammar:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1524.htm


Also, there are a similiar 'closed issue' to reopen (the former is to open) a
namespace. This issue is older than the previous proposal:

311. Using qualified name to reopen nested namespace
http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html


I couldn't see any of these 'features' into the current C++ draft.
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2007/n2461.pdf
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top