r/cpp_questions • • 9d ago

OPEN cpp class vs namespace

in my personal opinion, at least half of the purpose of using nested namespace is to manage visibility, the rust's mod allows it but cpp's namespace does not, only class allows it( the public and private)

is using classes with static functions inside everywhere instead of using namespace an already existing way to use the "namespace" in a way that i can more conveniently manage visibility?

3 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/kitsnet 9d ago

avoiding naming conflicts is the original design intention, but in practice unless for very very large projects there will seldom be the need of avoiding naming conflicts

"Very very large projects" is what C++ these days is about.

for the second drawback, i think it matters more, but it is still nice if in future versions of cpp i can have private/public in namespaces

As long as you cannot seal namespaces against injection of other functions into them, "private/public" in namespaces has no utility.