definition: MyClass.hpp
member functions (implementation): MyClass.cpp
And let's also say that as part of the implementation (MyClass.cpp) I require a std::vector<MyClass> that is shared across all MyClass instances.
Usually I would declare this as a static member of MyClass, but since std::vector<MyClass> requires the full definition of MyClass, I cannot declare this within MyClass itself (correct?). So I was thinking of instead using an empty namespace within the MyClass.cpp file. Is this good practice?
I figure it accomplishes my objectives:
- vector doesn't pollute namespace (outside of MyClass.cpp)
- vector is encapsulated (to visibility/use within MyClass)
- vector is shared among all instances of MyClass
Any considerations I'm failing to take into account? I am correct when believing ALL MyClass instances program-wide will access the SAME vector? Any situations where this isn't the case? Is this even true if MyClasses are instantiated in different threads?
Also, I find empty namespaces in general very interesting at the moment. I would enjoy any info, uses, and anecdotes about them you'd be willing to share.