Problem Description
When looking at Irrlicht source code, notice the following inheritance method:
Class Irrlichtdevice:public Virtual irefencecounted
{
...
};
Puzzled, then turn over the book to find answers, really is the book did not seriously look ah, at the same time read the code is a good way to learn.
Virtual Inheritance Description
In the "C + + Primer" Chinese version of the fifth edition of the No. 717 page of the author gave an example of "1" very good explanation of the situation, here I have complied.
The iostream and ostream of the IO standard library each inherit a common abstract base class named Base_ios. The abstract base class is responsible for saving the buffered content of the stream and managing the condition state of the flow. Iostream is another class that inherits directly from IStream and Ostream and can read and write the contents of the stream at the same time. Because IStream and Ostream both inherit from Base_ios, so iostream inherited Base_ios two times, once through IStream, another through ostream.
This leads to a problem where a iostream object is sure to want to operate in the same buffer. So if there are two copies, then the above share will not be realized.
In C + +, the purpose of virtual inheritance is to make a class declare a promise to share its base class. Where the shared base class sub-object is called the virtual base class. Thus, no matter how many times the virtual base class appears in the inheritance system, only one shared virtual base class sub-object is included in the derived class.
Simply put, in order to solve B, c simultaneously inherit a, and D inherits B, C, D has two copies of a in the question "2".
Reference Index
"1" "C + + Primer Chinese Version": Fifth edition, (United States) Lippmann (lippman,s.b), (United States) Lajoie (Lajoie,j.), (United States) (MOO,B.E.)
"2" http://bbs.chinaunix.net/thread-1782309-1-1.html
C + + virtual inheritance