I\'m just teaching myself C++ namespaces (coming from a C# background) and I\'m really starting to think that even with all the things that C++ does better than most other l
what I do when forward declaring looks like this:
namespace abc { namespace sub { namespace subsub { class MyClass; }}}
My forward declarations are collapsed into single line. Readability of forward declaration is sacrificed in return for the readability of the rest of code. And for definitions I don't use indentations either:
namespace abc {
namespace sub {
namespace subsub {
class MyClass
{
public:
MyClass();
void normalIntendationsHere() const;
};
}
}
}
Using this style requires a bit of discipline at the beginning, but it's the best compromise for me.
Since C++17 you can declare namespace with a syntax proposed by the author of the question.
namespace A::B::C { ... }
nested namespace definition:
namespace A::B::C { ... }
is equivalent tonamespace A { namespace B { namespace C { ... } } }
.
https://en.cppreference.com/w/cpp/language/namespace