虚拟继承是C++编程语言里的一种语法,使得派生类如果继承基类多次,但只有一份基类的拷贝在派生类对象中。
另外,永远不要忘记,虚拟继承的对象有指向基对象的基指针。
In addition, keep in mind that virtually inherited objects have base Pointers to address base objects.
多重继承可能使我们不必处理后续的问题,但它也重新将我们引向了虚拟继承,而这是绝对要避免的。
Multiple inheritance might save us from the latter problem, but it would also lead us back to virtual inheritance, which we definitely want to avoid.
例如,Microsoft Compiler 使用进程无关的偏移量来为虚拟继承类指定基对象,因而不存在这个问题。
For instance, Microsoft Compiler uses process-neutral offsets to address base objects for virtually inherited classes: thus, this issue does not arise.
应用推荐