This is the first time I used the multi-INHERITANCE OF C ++ and suffered a major setback. I was born stupid and did not have a strong understanding, so I never dared to touch this thing before. This time, I was forced to drive evil ideas. Not much nonsense. Please refer to the following situations:
I have a class
Class {
STD: vector <int> VEC;
};
Another Class B
Class B {
;
};
Now we use Class C to inherit a and B,
Class C: Public,
Public B {
;
};
Now I have an instance:
A * A = new C;
For some reason, I want to call the function B. I only have the following:
(B *) A-> Foo ();
In this case, if foo is useful to class member variables, the variable address may be incorrectly Accessed at this time. (Or errors may not occur. Everything depends on the compiler)
The perfect method is as follows:
(C *) A-> Foo ();
In this way, there will be no problems. But as you can see, this method is too ugly. It seems that the existence of multiple inheritance itself is redundant. We always have a way to avoid it, just like using Java. But the magic of C ++ is here to provide you with infinite possibilities and let you try, but the consequence may be heaven or the abyss.