What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?



What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?..

Answer / Aakash Bajpai

Multiple inheritance in C++ refers to a class that inherits from more than one base class. Virtual inheritance is a type of multiple inheritance where the same base class appears multiple times within a hierarchy but with a `virtual` specifier, ensuring that there will be only one object of the common base class shared by all derived classes. Advantages include code reuse and easier implementation of some design patterns; disadvantages include increased complexity and the diamond problem (ambiguity when deriving from multiple bases with the same member).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

1 Answers  


Implement strcmp

3 Answers   Bloomberg, Citadel,


What are virtual functions and what is its use?

1 Answers  


plz send me National informatics center paper pattern

1 Answers  


A milk carton can hold 3.78 litres of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one litre of milk is $0.38, and the profit of each carton of milk is $0.27. Write a C++ program that prompts the user to enter the total amount of milk produced in the morning. Then display the number of milk cartons needed to hold milk, the cost of producing milk, and the profit for producing milk.

2 Answers  


What is virtual destructor? What is its use?

1 Answers  


What is the use of endl in c++ give an example?

1 Answers  


Why was c++ made?

1 Answers  


What happens if a pointer is deleted twice?

1 Answers   Flextronics,


What are the two types of comments, and how do they differ?

1 Answers  


Why Pointers are not used in C++?

1 Answers   Global Logic,


What are virtual functions in c++?

1 Answers  


Categories