I'm having trouble understanding when/if single/multiple inheritance should be used vs forward declaration & I'd like to get a better understanding of it in the following example. If someone could point me in the right direction, or explain differences between them, it would be much appreciatd.
Following is sample of data structure I'm dealing with;
There exists 1 Parent, 1 SubParent & many different Children types. ie there's many Children per SubParent per Parent. Some Children need access to other Children objects. Children will use similar functions to each other ie ParseSelf/Display/Save/Edit. If Children get changed (ie Edit/Save), also need to update data in SubParent, Parent & possibly other Children.
I'm wanting to know what would be best way to implement something like this? I've come up with two alternatives below. If more clarification/information is needed please let me know.
class SubParent;
class Children;
class Parent
{
...
int iParent;
SubParent *pSubParent;
};
class SubParent
{
...
int iSubParent;
std::list<Children> childrenList;
};
class Children
{
...
int iChild;
int ChildType;
char *pData;
};
versus;
class Parent
{
...
int iParent;
};
class SubParent : public Parent
{
...
int iSubParent;
};
class Children : public SubParent
{
...
int iChild;
int ChildType;
char *pData;
};
Thank you.
EDIT: Main job of Parent; maintains information about file ie location of SubParent, SubParent size, total size of all data including self. Main job of SubParent; contains information about Children ie size & location of Children. Both Parent/SubParent don't really do much else except keep these items upto date.