虚拟继承是C++编程语言里的一种语法,使得派生类如果继承基类多次,但只有一份基类的拷贝在派生类对象中。
为了做到这一点,你要让从它直接继承的所有的 claes(类)使用 virtual inheritance(虚拟继承):cla File { ..
基于812个网页-相关网页
...易考,而涉及到类的时候,又不得不说类的继承,虚继承,虚函数,所以涉及到了类的内存布局,其中关于虚拟继承(virtual public)这个话题比较难以理解,而且不同的编译器环境可能实现的类的内存布局不同,所以本文仅在ms vs2010编译环境下调试,如果你在像cfr...
基于8个网页-相关网页
...7 章 Class 的继承(Inheritance)与子类型化(Subtyping) 321 第18 章 多继承与虚拟继承(Multiple and Virtual Inheritance) 361 第19 章 在 C++ 中使用继承机制 387 第20 章 iostream 库 397 索引(Index) 423 C++ Primer 3/e Answer Book 1 1 起步走 G...
基于1个网页-相关网页
虚拟继承下的 Virtual Functions
另外,永远不要忘记,虚拟继承的对象有指向基对象的基指针。
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.
应用推荐