KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I came across the diamond problem and found different solutions for different cases with a single diamond. However I couldn't find a solution for 'chained' diamonds. According to the structure: yes, I want to have multiple baseclasses everytime, so virtual inheritance isn't a solution (is it even called diamond then?). I also wanted to avoid get/set-functions for every middle-layer of a diamond. p p | | k k \ / s class parent { int val; }; class kid1 : public parent {}; class kid2 : public parent {}; class school : public kid1, public kid2 {}; Accessing val in the parent class works now like follows: school* s = new school; s->kid1::val=1; // works But what about the next 'chained' diamond: p p p p | | | | k k k k \ / \ / s s | | c c \ / w class country1 : public school {}; class country2 : public school {}; class world : public country1, public country2 {}; Accessing val via: world* w = new world; w->country1::kid1::val=1; // error results in: error: ‘kid1’ is an ambiguous base of ‘world’ Why? Isn't the route to the value well defined?
Tags (comma-separated)
Save Edits
Cancel