Sample Question #129 (programming – C++)
What’s the difference between virtual and nonvirtual base classes?
[Source: exercise 14.6 in Prata, C++ Primer Plus, 5th edition]
Sample Question #129 (programming – C++)
What’s the difference between virtual and nonvirtual base classes?
[Source: exercise 14.6 in Prata, C++ Primer Plus, 5th edition]
ANSWER
If two lines of inheritance for a class share a common nonvirtual ancestor, the class winds up having two copies of the ancestor’s members. Making the ancestor class a virtual base class solves this redundancy problem.
[Adapted from Prata’s answer]