Multiple inheritance without virtual functions in c++

后端 未结 2 657
心在旅途
心在旅途 2021-02-14 06:18

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.

相关标签:
2条回答
  • 2021-02-14 06:55

    It is. The error is due to a bug in your compiler.

    0 讨论(0)
  • 2021-02-14 07:10

    s->kid1::val does not mean "val from the kid1 subobject". It's just a name qualified by the type (not the subobject) that contains it.

    I don't know why country1::kid1 is even accepted at all, but apparently it's a typedef for ::kid1. Two data members in world both have the qualified name ::kid1::val.

    What you want is:

    world* w = new world;
    country1* const c1 = world;
    c1->kid1::val = 1;
    
    0 讨论(0)
提交回复
热议问题