Notes:
- Consider using mutator methods
- Please http://sscce.org/ - your example seems a bit over the show - would be easier to give you a clear example of how to solve your problem if your example in the problem was infact sscce. Either way, its still sufficient and your problem is clear enough I guess.
Answers:
- Why does
class TextEditor
not also inherit fromclass Control
andclass Caption
? This would seem like the obvious solution - you would have to use virtual inheritance forclass TextBox
still though. If 1 is not an option - then there is this - but in this limited sample HasText and Focusable seems to be pointless when compared to Caption and Control respectively.
class HasText { public: virtual string& text() { return text; } virtual const string& text() const { return text; } private: text }; class Focusable { public: virtual bool& focused() { return focused; } virtual const bool& focussed() const { return focussed; } }; class Control : public virtual Focusable { }; class Caption : public virtual Control, public virtual HasText { }; class Frame : public virtual Control { }; class TextEditor : public virtual HasText, public virtual Focusable { }; class Textbox : public virtual Caption, public virtual Frame, public virtual TextEditor { };