My class is mainly a container for a container, should I expose this fact?

In my design, I have a class that is basically the front for std::vector<OtherClass> . Should I pass a std::iterator to any caller in my class interface, pass a link to the entire vector or provide a set of functions to access the contents of my vector ? Or do you come up to him?

Additional information: Elements in the container will be installed during initialization and will not be added if the program is working normally. The clients of my class often execute queries and change the state of OtherClass elements, although not critically.

+8
c ++ design abstraction standard-library
source share
1 answer

You must create functions to change the internal vector. That's why:

Depending on the compiler, you can run different versions of the STL (Standard Template Library), which can cause unforeseen problems, hypothetically they can change the way std :: vector works when it is created in an older (or newer) version of the library and send it.

However, I assume that this is not a library, or a project that could potentially be used with another compiler. You can send a link or a pointer to a vector while you execute and compile with the same version of STL.

+1
source share

All Articles