I
Immortal Nephi
You may have heard diamond shape. You create one base class. One
base class has member functions and member variables. You create two
derived classes. All member functions and member variables from one
base class are inherited into two derived classes.
You want both derived classes to share member variables of the one
base class. You can do this way so you don't need keyword -- friend.
You can add virtual public One_Base_Class on both derived classes.
You need to create fourth derived class. Fourth derived class is
derived from both (two) derived classes. All four classes look like
diamond shape. It does the same what IOS looks like.
What happen if you want multiple diamonds? You can create two
diamonds. Then another class is dervied from both diamonds. You do
too many derived classes as long as more diamonds are related together
and very complex.
Finally, the last bottom class is derived from multiple diamond
classes. All member functions and member variables from the top base
class are inherited down to the last bottom class through multiple
diamonds.
What happen to a large vtable in the bottom class?. A large vtable
contains hundreds or thousands of member functions and hundreds of
member variables. You may want to define one pointer to member
function variable. Then pointer to member function variable can be
called to access thousands of member functions.
According to my test, only single pointer to member function variable
with thousands of member functions are much faster than sub-member
functions. Let's say that each main member functions (total 256 main
member functions) have 16 sub-member functions. Combined with main
member functions and sub-member functions are slow because it requires
extra overhead CPU time. Only single main member functons (total
4,096 main member functions) are faster.
Please let me know what you think about multiple diamonds. You know
what my writing means, but I do not need to provide sample source
code. It is easier to understand my post.
Nephi
base class has member functions and member variables. You create two
derived classes. All member functions and member variables from one
base class are inherited into two derived classes.
You want both derived classes to share member variables of the one
base class. You can do this way so you don't need keyword -- friend.
You can add virtual public One_Base_Class on both derived classes.
You need to create fourth derived class. Fourth derived class is
derived from both (two) derived classes. All four classes look like
diamond shape. It does the same what IOS looks like.
What happen if you want multiple diamonds? You can create two
diamonds. Then another class is dervied from both diamonds. You do
too many derived classes as long as more diamonds are related together
and very complex.
Finally, the last bottom class is derived from multiple diamond
classes. All member functions and member variables from the top base
class are inherited down to the last bottom class through multiple
diamonds.
What happen to a large vtable in the bottom class?. A large vtable
contains hundreds or thousands of member functions and hundreds of
member variables. You may want to define one pointer to member
function variable. Then pointer to member function variable can be
called to access thousands of member functions.
According to my test, only single pointer to member function variable
with thousands of member functions are much faster than sub-member
functions. Let's say that each main member functions (total 256 main
member functions) have 16 sub-member functions. Combined with main
member functions and sub-member functions are slow because it requires
extra overhead CPU time. Only single main member functons (total
4,096 main member functions) are faster.
Please let me know what you think about multiple diamonds. You know
what my writing means, but I do not need to provide sample source
code. It is easier to understand my post.
Nephi