Let's look at the drawbacks of using virtual inheritance
- various overheads in object size and performance will be incurred:
slower access to base class members and slower casts (including
implicit ones), and one pointer added to instances for each
base class.
Oh I just realized something (I think):
Just as how an object contains a hidden pointer to a virtual function... as
in:
class Blah
{
private:
char* t;
public:
int k;
virtual int Monkey(double k)
{
return 87;
}
};
An object of "Blah" might look something like the following in memory:
------------------------------------
| Pointer to the function "Monkey" |
------------------------------------
| t |
------------------------------------
| k |
------------------------------------
Well... similarly, if you have the following:
class Ape {}
class Monkey : virtual public Ape { int rent; }
Might an object of "Monkey" look like the following in memory?:
-----------------------------
| Pointer to the Ape object |
-----------------------------
| rent |
-----------------------------
That would explain why it's called "virtual inheritance". Am I right?
-JKop