M
mac_ferrari1975
Hi all,
Consider the situation. I am designing class library and I have a class
A. I derived class B and class C from A but derivation is not virtual.
for exa.
class A {};
class B : public A {};
class C : public A {};
So when I am designing this library, after research I come to
conclusion that nobody will derive from class B and class C together.
So I decided not derive it virtually. But in infinite future, if
somebody wants to derive from B and C, it will create two copy of A in
the derived class, let's call it D.
Now that person doesn't have access to modify my class library and if
he wants to reuse my code and derive from B and C together, will have
problem of having duplicate copy of A in the object of class D. Assume
that he has strong memory constraints and no way can afford to have
duplicate copy of A inside D.
So even though code is resuable, he can't use it. What can be the
solution of this? Does it mean I should always use virtual inheritance
during creation of B and C? Is there any drawback if I use virtual
inheritance all the time?
Thanks.
Consider the situation. I am designing class library and I have a class
A. I derived class B and class C from A but derivation is not virtual.
for exa.
class A {};
class B : public A {};
class C : public A {};
So when I am designing this library, after research I come to
conclusion that nobody will derive from class B and class C together.
So I decided not derive it virtually. But in infinite future, if
somebody wants to derive from B and C, it will create two copy of A in
the derived class, let's call it D.
Now that person doesn't have access to modify my class library and if
he wants to reuse my code and derive from B and C together, will have
problem of having duplicate copy of A in the object of class D. Assume
that he has strong memory constraints and no way can afford to have
duplicate copy of A inside D.
So even though code is resuable, he can't use it. What can be the
solution of this? Does it mean I should always use virtual inheritance
during creation of B and C? Is there any drawback if I use virtual
inheritance all the time?
Thanks.