开发者

Derived class linker - is this wrong?

We have this situation:


                    Window  Keyboard
                    ^         ^
   开发者_StackOverflow                 |        /
                    ApplicationWindow 

so

class Window { }
class Keyboard { }
class AppWindow : public Window, public Keyboard { }

Now, Keyboard wants to access a property in ApplicationWindow, for example, it wants to call the ApplicationWindow's getWidth() property.

The solution I have is to place a pointer to an ApplicationWindow inside Keyboard.

I'm trying to use multiple inheritance here as composition, while I know actual composition is more strongly encouraged, I wanted to try MI.

In any case I'd need a back link to the ApplicationWindow instance from Keyboard if I used composition anyway..


I would say it would be a lot cleaner to move the property into the base class Keyboard.

ApplicationWindow would have access to it as well since ApplicationWindow extends Keyboard.

You don't want the base class to need to have any knowledge of any sub classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜