随笔分类 -  C/C++

摘要:对于一般的对象,如:int a = 10;int b = 20;它们之间的赋值、复制过程是很简单的。但是对于类对象来说,其内部存在各种类型成员变量,在拷贝过程中会出现问题。如下: 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 class String { 5 public: 6 String (const char* psz=NULL) : m_psz(strcpy(new char[strlen(psz?psz:"")+1]),psz?psz:"&quo 阅读全文
posted @ 2013-01-08 22:08 ZeroTiny 阅读(2048) 评论(5) 推荐(3)
摘要:首先,何为钻石继承,顾名思义,在类的继承过程中,继承结构是一个类似菱形(钻石)的结构就属于钻石继承,如下: 这是一个最简单的钻石继承。实际上,在复杂的继承表中,只要子类按不同的继承路径回溯到基类有菱形结构,均属钻石继承。下面先看一个例子,钻石继承在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 阅读(2903) 评论(2) 推荐(5)