I have a case similar to "The diamond of death"
I have class B and C which Virtually Inherit Class A, and also Class D which Inherit Classes B and C.
A
/ \
B C
\ /
D
B & C has inherited members, and also their own members. D has only inherited members.
I'm writing Save method which gets ofstream and should write the Object to a binary file.
And a Load method which gets ifstream and should create the object from a binary file.
The Method are virtual and written in such a way that each class Method handles only that specific class members Load & Save (and uses the inherited classes methods for the rest of the inherited members)
Now when writing the Save method for D, basically I only need to do:
B.save();
C.save();
Obviously this will cause A.save() to be called twice which will cause A to be written to the file twice
I think something like add a saveOnly method to B and C which will save only their members (and not A's) is silly
So I wonder what is the Best Practices for such a case ?