Answer the question
In order to leave comments, you need to log in
Multiple call to base class constructor with virtual inheritance?
There is the following code:
class A {
private: int a;
public: A(int a) : a(a) {}
};
class B : public virtual A {
private: void* b;
public: B(int a) : A(a) { b = malloc(8); }
};
class C : public virtual A {
private: void* c;
public: C(int a) : A(a) { c = malloc(16); }
};
class D : public C {
private: void* d;
public: D(int a) : C(a) { d = malloc(32); }
};
class D : public C {
private: void* d;
public: D(int a) : A(a), C(a) { d = malloc(32); }
};
Answer the question
In order to leave comments, you need to log in
this begs the question "Will the base class constructor A be called twice, because constructor A is also called in constructor C?".
A mem-initializer where the mem-initializer-id denotes a virtual base class is ignored during execution of a constructor of any class that is not the most derived class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question