J
Johan Nilsson
[ This is a slightly modified re-post from c.l.c++.m ]
I've seen many alternatives when it comes to referring to types defined
in parent/sibling/other namespaces. Consider the following hypothetical
namespace layout:
namespace company {
namespace lib {
class SomeClass {};
namespace module1 {
class SomeOtherClass {};
} // module1
namespace module2 {
...
} // module2
} // lib
} // company
In a header file, from inside company::lib::module2, what would be the
preferred way to refer to:
1. std::vector
2. company::lib::SomeClass
3. company::lib::module1::SomeOtherClass
I've got a few alternatives myself:
1(a) '::std::vector'
1(b) 'std::vector'
2(a) '::company::lib::SomeClass'
2(b) 'company::lib::SomeClass'
2(c) 'lib::SomeClass'
2(d) 'SomeClass'
3(a) '::company::lib::module1::SomeOtherClass'
3(b) 'company::lib::module1::SomeOtherClass'
3(c) 'lib::module1::SomeOtherClass'
3(d) 'module1::SomeOtherClass'
Each one of the the alternatives has its pros and cons in terms of
readability and stability (not being affected by someone e.g.
introducing company::lib::module2::SomeClass in combination with
alternative 2(d) above).
What do you do in practice (assuming you do use nested namespaces)? I'd
especially appreciate comments backed by some real-world experience
maintaining libraries/applications.
// Johan
I've seen many alternatives when it comes to referring to types defined
in parent/sibling/other namespaces. Consider the following hypothetical
namespace layout:
namespace company {
namespace lib {
class SomeClass {};
namespace module1 {
class SomeOtherClass {};
} // module1
namespace module2 {
...
} // module2
} // lib
} // company
In a header file, from inside company::lib::module2, what would be the
preferred way to refer to:
1. std::vector
2. company::lib::SomeClass
3. company::lib::module1::SomeOtherClass
I've got a few alternatives myself:
1(a) '::std::vector'
1(b) 'std::vector'
2(a) '::company::lib::SomeClass'
2(b) 'company::lib::SomeClass'
2(c) 'lib::SomeClass'
2(d) 'SomeClass'
3(a) '::company::lib::module1::SomeOtherClass'
3(b) 'company::lib::module1::SomeOtherClass'
3(c) 'lib::module1::SomeOtherClass'
3(d) 'module1::SomeOtherClass'
Each one of the the alternatives has its pros and cons in terms of
readability and stability (not being affected by someone e.g.
introducing company::lib::module2::SomeClass in combination with
alternative 2(d) above).
What do you do in practice (assuming you do use nested namespaces)? I'd
especially appreciate comments backed by some real-world experience
maintaining libraries/applications.
// Johan