|
-
July 26th, 2009, 02:55 PM
#2
Re: Call a function in a higher level class?
Some code or pseudo code would be useful here.
I'll try to surmise.
Code:
class Acct
{
AcctTabs * m_tbctrl;
};
class AcctTabs
{
AcctList * tabAcctList;
};
class AcctList
{
Acct * acct;
void func()
{
acct->UpdateNames();
}
};
AcctList is a child of a child which needs to 'know' the parent of it's parent in order to make the call.
AcctList must therefore obtain a pointer to the appropriate instance of Acct, by whatever initialization path can be fashioned.
There must be some point where the m_tbctrl is set to the appropriate child. At that point, AcctTabs should probably obtain a pointer to it's parent.
Likewise, there must be some point where tabAcctList is set to it's child, and at that point the AcctList could receive it's parent.
Code:
class Acct
{
AcctTabs * m_tbctrl;
};
class AcctTabs
{
Acct *parent;
AcctList * tabAcctList;
};
class AcctList
{
AcctTabs *parent;
Acct * acct;
void func()
{
parent->parent->UpdateNames();
}
};
Obviously this parent to parent is uncomfortable, but workable, so at the point where AcctList sets it's AcctTabs * parent, it could also obtain acct...
acct = parent->parent;
Last edited by JVene; July 26th, 2009 at 02:59 PM.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|