fwd: from jjhou's web

0 篇文章 0 订阅

轻松一点的东西

> 同一个 class:
>
> class array {
> public:
> int a[2];
> array update() {
> a[0]=a[0]*3;
> a[1]=a[1]*3;
> return(*this); }
> };

>
> 两个不同的 main:
>
> main()
> {
> array n;
> n.a[0]=1; n.a[1]=2;
> n.update();
> n.a[0]=0;
> cout << n.a[0] << endl << n.a[1] << endl;
> }
>
> main()
> {
> array n;
> n.a[0]=1; n.a[1]=2;
> (n.update()).a[0]=0; //
两行合并成一行
> cout << n.a[0] << endl << n.a[1] << endl;
> }


太多的写作毛病:

a. Effctive C++:
条款20:避免将 data members 放在公开介面中
Item 20: Avoid data members in the public interface.

b. Effctive C++:
条款22:尽量使用 pass-by-reference(传址),少用 pass-by-value(传值)
Item 22: Prefer pass-by-reference to pass-by-value.

c. Effctive C++:
条款29:避免传回内部资料的 handles
Item 29: Avoid returning "handles" to internal data.

d. More Effctive C++:
条款19:了解暂时性物件的来源
Item 19: Understand the origin of temporary objects

e. More Effctive C++:
条款22:考虑以复合运算子 op= 取代单一运算子 op
Item 22: Consider using op= instead of stand-alone op

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值