2014年6月28日

C++-多重继承的注意点

摘要: 1, 钻石型多重继承如果不想要底部的类有重复的变量,则需要声明为virtual继承 class File{...}; class InputFile: virtual public File{..}; class OutputFile: virtual public File{....}; ... 阅读全文

posted @ 2014-06-28 19:09 醉清风JM 阅读(595) 评论(0) 推荐(0)

C++-继承名称的掩盖

摘要: /////////////////////////////////////////////////////////////////////////////////// FileName : effect_item33.h// Version : 0.10// Author... 阅读全文

posted @ 2014-06-28 18:13 醉清风JM 阅读(172) 评论(0) 推荐(0)

C++-dynamic_cast的用处

摘要: 主要用来在没有实现文件,只有头文件的情况下,添加派生类的功能,如下例给programmer加奖金。注意:dynamic_cast不能用于没有virtual函数的类/////////////////////////////////////////////////////////////////////... 阅读全文

posted @ 2014-06-28 15:16 醉清风JM 阅读(516) 评论(0) 推荐(0)

C++-const_cast, reinterpret_cast, static_cast的用法

摘要: /////////////////////////////////////////////////////////////////////////////////// FileName : cast_item27.cpp// Version : 0.10// Author... 阅读全文

posted @ 2014-06-28 15:12 醉清风JM 阅读(254) 评论(0) 推荐(0)

C++-高效的swap

摘要: 原始版本:templatevoid swap(T& a, T& b){ T tmp(a); a = b; b = tmp;}此版本不重视效率,当交换的两个对象比较大时,需要更高效的交换,因此应该提供1)public swap成员函数,让它高效的置换两个对象,并提供nono-memb... 阅读全文

posted @ 2014-06-28 15:01 醉清风JM 阅读(581) 评论(0) 推荐(0)

C-crash的方法

摘要: #include using namespace std;int main(){#if 0 //devide by 0 int i = 1; int j = 0; double d = i/j;#endif #if 1 //allocate large memor... 阅读全文

posted @ 2014-06-28 11:08 醉清风JM 阅读(286) 评论(0) 推荐(0)

C++-bool的值

摘要: /////////////////////////////////////////////////////////////////////////////////// FileName : bool_value.cc// Version : 0.10 created ... 阅读全文

posted @ 2014-06-28 11:06 醉清风JM 阅读(364) 评论(0) 推荐(0)

C++-Effective C++ Items

摘要: Item2:尽量以const,enum,inline替换#define原因:1, #define ASPECT_RATIO 1.63 编译错误时产生魔数,应以const double Aspect_Ratio = 1.63替换 2, #define不能提供作用域,如某个类的常量 ... 阅读全文

posted @ 2014-06-28 09:20 醉清风JM 阅读(561) 评论(0) 推荐(0)

导航