Does multiple virtual inheritance have late binding, such as virtual function inheritance?

Unlike virtual function inheritance, resolving virtual inheritance seems to be shortened and dry, but maybe I'm just not creative enough (insidious?).

Is virtual inheritance generally related to inheritance of virtual functions? In particular, will virtual inheritance lead to late binding? I see no reason. I am only suspicious due to keyword overload.

I understand that the standard does not define the implementation of virtual inheritance. I'm interested in everything that most non-hypothetical machines do, however imperfect.

+4
source share
2 answers

Virtual inheritance is not without the cost of execution time, but the reason for this cost is not increased flexibility, but the resolution of ambiguity.

, , , C A . A::foo C ( ). this, -. , , , A C, , this - , , .

, A::foo C, C. : , , - this, A , , , A C.

class A {
public:
    void foo();
    [...]
};
class B1 : public A {};
class B2 : public A {};
class C : public B1, public B2 {};

C c;
B1* b1 = &c;
B2* b2 = &c;

//assume foo() changes some internal state of A
b1->foo();
//the state change of the previous line is not visible
//to the next call - they operate on distinct instances of A
b2->foo();

virtual . A . A::foo, , . C A .

class B1 : virtual public A {};
class B2 : virtual public A {};
[...]

C c;
B1* b1 = &c;
B2* b2 = &c;

//both calls will now operate on the same instance of A
//state changes performed by the one will be observed by the other
b1->foo();
b2->foo();
+1

, -, , , . , baseClassInstance->dataMember . virtual "vtables" .

. " " , Edsko de Vries, , GNU Compiler Cluster (gcc) , , .. , .

+5

Source: https://habr.com/ru/post/1546651/


All Articles