I have MyClass that hide the container inside it, I want to control when new item is added to the container and when an item is to be deleted from container, but i don’t need to control read-only operation such as getter function
class MyClass {
protected:
std::vector<MySubClass> subclasses;
public:
}
for interfacing with the user of MyClass, should I implement interface function such as :
addSubClass(), getSubClassAt(int ), getSubClassIndex(MySubclass ), delSubClass().
or its better just return const iterator, for readonly operation :
std::vector<MySubClass>::const_iterator getSubclassIterator();
and provide special write-operation function such as
addSubClass(), delSubClass().
or is there is a better way than these?
If you invent your own member functions for manipulating the internal list of objects, then I will have to learn your interface when I want to use your class.
I much rather you use the conventions of the standard library, which I already know, so I can use your class immediately: