Is there a more succinct way to define a class in a namespace than this:
namespace ns { class A {}; }
I was hoping something like class ns::A {};
would work, but alas not.
Is there a more succinct way to define a class in a namespace than this:
namespace ns { class A {}; }
I was hoping something like class ns::A {};
would work, but alas not.
No you can't. To quote the C++ standard, section 3.3.5:
So the declaration must be inside a namespace block - the definition can of course be outside it.
You can do that, but it's not really more succint.
Or
You're close, you can forward declare the class in the namespace and then define it outside if you want:
What you cannot do is define the class in the namespace without members and then define the class again outside of the namespace. That violates the One Definition Rule (or somesuch nonsense).
The section you should be reading is this:
Note the term -- declaration so D.Shawley (and his example) is correct.