Which keyword is used with a base class in C++ to implement virtual inheritance?

Options

  • A. virtual
  • B. static
  • C. friend
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. virtual

Detailed Explanation

Answer: virtual

The virtual keyword is used when specifying virtual inheritance.

For example:

class B : virtual public A { };

Here, class B virtually inherits class A. If another class later inherits from multiple classes derived from A, only one shared A subobject is maintained.