M
MRe
Hi,
This has been driving me crazy for the last few days, hopefully
someone can enlighten me?
As an example of what I'm trying to do, take the following class
structure (memory management not included, maybe take it to be more
pseudo code)
class TreeBranch
{
int AddItem() { (*items)[++nextItem] = new TreeItem(); return
nextItem; }
TreeItem * GetItem(int Index) { return (*items)[Index]; }
TreeItem * * items;
}
class TreeItem
{
int AddBranch() { (*branches)[++nextBranch] = new TreeBranch();
return nextBranch; }
TreeCollection * GetBranch(int Index) { return (*branches)
[Index]; }
TreeCollection * * branches;
}
How can I make this work, as both classes need to allocate the other
(this is the crux of the problem, everything else here is fluff)? I've
been trying to reorganise the code to remove the circular reference
with interfaces and class factories but I just cannot figure out how
to do it
Anyone any suggestions?
Thank you kindly,
Regards,
Eliott
This has been driving me crazy for the last few days, hopefully
someone can enlighten me?
As an example of what I'm trying to do, take the following class
structure (memory management not included, maybe take it to be more
pseudo code)
class TreeBranch
{
int AddItem() { (*items)[++nextItem] = new TreeItem(); return
nextItem; }
TreeItem * GetItem(int Index) { return (*items)[Index]; }
TreeItem * * items;
}
class TreeItem
{
int AddBranch() { (*branches)[++nextBranch] = new TreeBranch();
return nextBranch; }
TreeCollection * GetBranch(int Index) { return (*branches)
[Index]; }
TreeCollection * * branches;
}
How can I make this work, as both classes need to allocate the other
(this is the crux of the problem, everything else here is fluff)? I've
been trying to reorganise the code to remove the circular reference
with interfaces and class factories but I just cannot figure out how
to do it
Anyone any suggestions?
Thank you kindly,
Regards,
Eliott