Hi all,
I have a problem with trying to call a protected base class function from an inherited class.
I have done some research and from what i can gather what i am trying to do is simply not permitted by the standard. The error i get when trying to compile is:
error: 'virtual void UIObject::onParentAttach(UIObject*)' is protected
The error is generated by:virtual void SimplePanel::add( UIObject* pChild )
So what i am trying to achieve is that i have two functions in my base class virtual void UIObject::onParentAttach( UIObject* pParent ); virtual void UIObject::onParentOrphan()
I want these to be used by container objects, and able to be reimplemented by other classes inheriting UIObject as necessary, but keep the functions out of the public API.
I can continue by making the UIObject functions public but thats not what i want, so i was hoping someone could throw some ideas out at how i can keep the functions out of public scope but still accessible by inheriting classes.
Thanks in advance :)
Stripped down source code follows:
//main.cpp
class UIObject
{
public:
virtual ~UIObject() { }
/* UIObject API */
protected:
UIObject( UIObject* pParent )
:
m_pParent(pParent)
{
}
virtual void onParentOrphan()
{
m_pParent = 0;
}
virtual void onParentAttach( UIObject* pParent )
{
m_pParent = pParent;
}
/* parent */
UIObject* m_pParent;
};
class Panel : public UIObject
{
public:
virtual ~Panel() { }
/* panel methods */
virtual void add( UIObject* pChild ) = 0;
protected:
Panel()
:
UIObject(0)
{
}
};
class SimplePanel : public Panel
{
SimplePanel() { }
virtual ~SimplePanel() { }
virtual void add( UIObject* pChild )
{
if( m_pChild )
{
m_pChild->onParentOrphan();
}
m_pChild = pChild;
m_pChild->UIObject::onParentAttach( this );
}
private:
UIObject* m_pChild;
};
int main() {
return 0;
}