r/cpp_questions • u/Equivalent_Union2768 • 7d 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
View all comments
10
u/kitsnet 7d ago
C++ namespaces are about avoiding name conflicts, not about visibility. One can add a new name or inject another namespace into an already existing namespace, one cannot do that with classes.
Part of the functionality of the namespaces is argument-dependent lookup.