Probably am I not clear enough. ^^ So here's an example, it is not the real code but just to explain the problem:
I have a pure abstract base class which serve as an interface.
Code:
class Window : public Object {
public:
Window() throw() {}
virtual ~Window() throw() {}
// other members
virtual Window *GetParent() const throw() = 0;
virtual void SetParent(Window *pNewParent) throw() = 0;
virtual void ChangeParent() throw() = 0;
virtual Window *FindChild(PSTR pCaption) const throw() = 0;
virtual void AddChild(Window *pChild) throw() = 0;
virtual void RemoveChild(Window *pChild) throw() = 0;
};
And now I have the real class:
Code:
// a pure helper interface which provides with the implementation
class Win32Window {
protected:
Win32Window() throw() {}
virtual ~Win32Window() throw() {}
// other members
// should I put the parent/child stuffs here?
// in this case, it would be
void SetParent(Win32Window *pNewParent) throw() // sets the parent window
{
this->pParent = pNewParent; // no problem here
// but how can I get the handle
// to my parent window from my interface?
// maybe a cast but...
}
void Create() throw(Exceptions::System) // create the window
{
this->Handle = CreateWindowEx(ExtendedStyle,
pClassName,
pCaption,
Style,
Left, Top,
Width, Height,
// no problem for now
pParent->GetHandle(),
hMenu,
hGlobalInstance,
NULL);
}
// helper functions that access the private members
INT GetStyle() const throw() { return this->Style; }
void SetStyle(INT NewStyle) throw() { this->Style = NewStyle; }
private:
Win32Window *pParent;
};
// here is a derived class from Win32Window, it serves as a base frame window
class Frame : public Window, private Win32Window {
public:
Frame() throw() {}
virtual ~Frame() throw() {}
// all inherited members
// virtual members as well
// binds the interface with the implementation
void SetParent(Win32Window *pNewParent) throw()
{
Win32Window::SetParent(/* what should I do? */
// I could do a cast... I don't know if it would work
// but I shouldn't,
// because I don't know if the real class provides
// a full interface compatibility with its implementation
// that is to say Win32Window
// besides, it probably does not as that class is to be
// privately inherited...
dynamic_cast<Win32Window *>(pNewParent)
);
}
protected:
using Win32Window::GetStyle() const throw(); // there is only the read accessor
// because I want the style
// to be the same for all
// frame windows
};
// even if I added a GetHandle() method, I couldn't just access it as it would
// be in Win32Window...