会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
williamwood
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
2014年7月5日
effective c++ 条款9 do not call virtual function in constructor or deconstructor
摘要: 在构造函数中不要调用virtual函数,调用了也不会有预期的效果。举个例子class Transaction{ public: Transaction() { log(); } virtual void log() =0;}class BusinessTran...
阅读全文
posted @ 2014-07-05 01:02 williamwood
阅读(348)
评论(0)
推荐(0)
2014年7月1日
effective c++ 条款8 prevent exception from leaving destructor
摘要: 1 析构函数绝对不要吐出异常。如果一个析构函数可能调用产生异常的函数,析构函数应该不传播该异常或结束程序2 如果客户需要对某个操作函数运行期间抛出的异常做出反应,那么class应该提供一个普通函数执行该操作。3 产生两个以上的异常会导致程序关闭或者不确定行为
阅读全文
posted @ 2014-07-01 03:18 williamwood
阅读(128)
评论(0)
推荐(0)
effective c++ 条款7 declare virtual destructor for polymophyc base class
摘要: 这似乎很明显。如果base class的destructor不是virtual,当其derived class作为基类使用,析构的时候derived class的数据成员将不会被销毁。举个例子 我们有个交通工具的类作为基类, 它的析构函数不是virtualclass transportTool{ ...
阅读全文
posted @ 2014-07-01 03:12 williamwood
阅读(252)
评论(0)
推荐(0)
2014年6月29日
effective c++ 条款6 如果不想要就要告诉大家
摘要: 这个条款应该和第五个放在一起编译器默认生成1 无参构造函数,2 析构函数3 拷贝构造函数4 赋值预算符当我们不需要,就要显示的告诉大家我们不需要。方法:自己声明这个函数为private,单不要定义它。原因:1 自己声明这个函数,编译器就不会为我们生成这个函数 2 声明成private,就不会被...
阅读全文
posted @ 2014-06-29 19:31 williamwood
阅读(165)
评论(0)
推荐(0)
2014年6月27日
effective c++ 条款5 c++ 默默实现的函数
摘要: 当写一个空类c++ 会为我们自动提供四个函数1 默认构造函数2 默认析构函数3 拷贝构造函数4 默认赋值运算符
阅读全文
posted @ 2014-06-27 03:47 williamwood
阅读(156)
评论(0)
推荐(0)
effective c++ 条款4 make sure that objects are initialized before they are used
摘要: 1 c++ 类的数据成员的初始化发生在构造函数前class InitialData{ public: int data1; int data2; InitialData(int a, int b) { ...
阅读全文
posted @ 2014-06-27 02:47 williamwood
阅读(179)
评论(0)
推荐(0)
2014年6月25日
effective c++ 条款3 use const whereever you can
摘要: 1 const 传达的意思应该是这个变量是常量不能更改2 const 在 * 左边表示数据是const,在右边表示指针是const // char greeting[] = "hello"; char* p = greeting; //const *: const data //...
阅读全文
posted @ 2014-06-25 03:32 williamwood
阅读(361)
评论(0)
推荐(0)
作为类的成员函数,重载运算符只能有一个参数
摘要: 1 overload a operator of a class, you can only use one para., this pointer is automatically used. class Rational { public: //not correct sinc...
阅读全文
posted @ 2014-06-25 03:17 williamwood
阅读(916)
评论(0)
推荐(0)
2014年6月23日
effective c++ prefer const,enum, inline to #defines
摘要: 学习心得对于纯常量,最好以const对象或者enums替换#define#define FIRST 3 //not goodenum{ first=1, second=2} ;int num[first];对于macros,最好用inline代替#define CALL_MAX(a, b) f(...
阅读全文
posted @ 2014-06-23 03:51 williamwood
阅读(143)
评论(0)
推荐(0)
2013年12月21日
测试
该文被密码保护。
阅读全文
posted @ 2013-12-21 23:24 williamwood
阅读(51)
评论(0)
推荐(0)
上一页
1
2
3
4
公告