This is a question about C++ design: how to avoid introducing a bug as a class changes. The question title indicates my point of view of what I want, but might be the wrong strategy.
I have a class called MyCell that I collect in another class called MyRow. Behind all of this is a database, and the row will, prior to destruction, want to persist itself to the database if any of its cells have changed.
class MyRowUser : public MyRow {
public:
MyRowUser() : MyRow() {}
MyCell<int> registered_user_id;
MyCell<int> birth_year;
MyCell<UserGender> gender;
};
class MyTableUser : public MyTable {
// Contains various things, including a collection
// of MyRowUser objects. Not relevant here, just
// for context.
}
Now this isn't hard: I just have a function called IsDirty() in MyRowUser (or MyRow if I'm clever enough) that loops over the MyCell values and asks each one if it has changed. If any has, then the row persists.
A class of error I'd like to avoid, however, is that I add a new MyCell member to a row and forget to add it to the IsDirty() function that loops over the cells. And here I have not found a clever solution. Every registration scheme I think of so that the row knows about the cells requires actually doing the registrations explicitly. Notably, the MyCell constructors can't know about the Row (about this) in any automatic way I've thought of.
Any design suggestions on how to achieve this more robustly than my current manual iteration?