Should every class have its own namespace?

Posted by thehouse on Stack Overflow See other posts from Stack Overflow or by thehouse
Published on 2010-04-01T22:44:08Z Indexed on 2010/04/01 22:53 UTC
Read the original article Hit count: 175

Something that has been troubling me for a while:

The current wisdom is that types should be kept in a namespace that only contains functions which are part of the type's non-member interface (see C++ Coding Standards Sutter and Alexandrescu or here) to prevent ADL pulling in unrelated definitions.

Does this imply that all classes must have a namespace of their own? If we assume that a class may be augmented in the future by the addition of non-member functions, then it can never be safe to put two types in the same namespace as either one of them may introduce non-member functions that could interfere with the other.

The reason I ask is that namespaces are becoming cumbersome for me. I'm writing a header-only library and I find myself using classes names such as project::component::class_name::class_name. Their implementations call helper functions but as these can't be in the same namespace they also have to be fully qualified!

© Stack Overflow or respective owner

Related posts about c++

Related posts about best-practices