Wednesday, May 10, 2006

C++ note: virtual inheritance

The format

public class C: virtual B {...}

The main reason for virtual inheritance is for the diamond structure - B extends D, C extends D and A extends B, C. Without virtual mark, the instances of A will include data slots defined in both B and C, while the data slots defined in B and C will each include the data slots from D .

Python's will always have a diamond structure, because it always uses references. Of course Java does not have such problems.

No comments: