This is my first post on stackoverflow so be gentle :)
I have standard diamond problem but I'd managed to sort it out.
class Control
{
public:
bool Focused;
};
class Caption : public virtual Control
{
public:
string Text;
};
class Frame : public virtual Control { };
class Textbox : public Caption, public Frame, public TextEditor { };
Sadly another problem with inheritance appeared. Class TextEditor
has common variable names:
class TextEditor
{
public:
bool Focused;
string Text;
};
Compiler gives me errors:
ambiguous access of 'Text'
ambiguous access of 'Focused'
But all I want is those variables from all classes to be merged in derived class 'Textbox'.
Thanks for any kind of help Sorry for any languages mistakes and/or question I'm asking.
Update
A little explanation cause I might have use wrong words. Sorry for that.
By 'merge' I meant that:
- If I use variables or methods of
Control
,Caption
orFrame
it will influence the values ofTextEditor
and vice versa. In other words variables are shared in derived class.
So my final class will look like this:
class Textbox : public Caption, public Frame, public TextEditor
{
public:
string Text;
bool Focused;
};
And not like this:
class Textbox : public Caption, public Frame, public TextEditor
{
public:
string Caption::Text;
bool Caption::Focused;
string TextEditor::Text;
bool TextEditor::Focused;
};
Which happening right now. Cause I can't do this:
Textbox A;
A.Text = "Text";
Because I have two variables with the name Text
. So I would have to do this:
Textbox A;
A.Caption::Text = "Text";
A.TextEditor::Text = "Text";
Best regards Lavi