摘要: 首先,何为钻石继承,顾名思义,在类的继承过程中,继承结构是一个类似菱形(钻石)的结构就属于钻石继承,如下: 这是一个最简单的钻石继承。实际上,在复杂的继承表中,只要子类按不同的继承路径回溯到基类有菱形结构,均属钻石继承。下面先看一个例子,钻石继承在C++程序设计中带来的问题。 1 //diamond.cpp 2 #include<iostream> 3 using namespace std; 4 class A{ 5 public: 6 A (int x) : m_x(x) {} 7 int m_x; 8 }; 9 class B : public A {... 阅读全文
posted @ 2013-01-03 21:39 ZeroTiny 阅读(2825) 评论(2) 推荐(5) 编辑