Interview Question: Virtual Enhancement

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]

This entry was posted in Sample Qs. Bookmark the permalink.

1 Response to Interview Question: Virtual Enhancement

  1. Brett says:

    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] 

Leave a reply to Brett Cancel reply