0xCyberY / The-diamond-problem-in-cpp

�The diamond problem The diamond problem occurs when two super classes of a class have a common base class. For example, in the following diagram, the TA class gets two copies of all attributes of Person class, this causes ambiguities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The-diamond-problem-in-cpp

�The diamond problem The diamond problem occurs when two super classes of a class have a common base class.

�In the give code constructor of ‘Person’ is called two times. Destructor of ‘Person’ will also be called two times when object ‘ta1’ is destructed. So object ‘ta1’ has two copies of all members of ‘Person’, this causes ambiguities. The solution to this problem is ‘virtual’ keyword. We make the classes ‘Faculty’ and ‘Student’ as virtual base classes to avoid two copies of ‘Person’ in ‘TA’ class.

About

�The diamond problem The diamond problem occurs when two super classes of a class have a common base class. For example, in the following diagram, the TA class gets two copies of all attributes of Person class, this causes ambiguities.


Languages

Language:C++ 100.0%