Scott Meyers的有效C ++ [英] Effective C++ by Scott Meyers

查看:87
本文介绍了Scott Meyers的有效C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在阅读这本书。

他正在迭代我自1996年以来的一些观点,例如

异常安全。

但是例如他错过了一个主要的异常安全指南,

这是


只在构造函数体内分配一个资源(deallocate
$ b在匹配的析构函数体中$ b。

将这样的类链接到基类/成员类关系中。

这样你就可以利用代码生成功能

编译器,

,因为您不必处理部分构造的对象,并且在抛出异常后进行
清理。


我以为这个规则已经广泛使用,应该是任何关于C ++的现代书籍的一部分。

I right now reading this book.
And he is iterating some points I''m following since 1996, e.g.
exception safety.
But e.g. he is missing one of the major exception safety guidelines,
which is

Allocate only a single resource inside a constructor body (deallocate
in the matching destructor body).
Chain such classes into base-class/member-class relationships.
This way you are able to exploit the code generation features of the
compiler,
since you wont have to deal with partially constructed objects and
cleanup after an exception has been thrown.

I was thinking that this rule is already in broad usage and should be
part of any modern book on C++.

推荐答案

Peter写道:
Peter wrote:

我现在正在读这本书。

他是迭代我自1996年以来跟随的一些点,例如

异常安全。

但是例如他错过了一个主要的异常安全指南,

这是


只在构造函数体内分配一个资源(deallocate
$ b在匹配的析构函数体中$ b。

将这样的类链接到基类/成员类关系中。

这样你就可以利用代码生成功能

编译器,

,因为您不必处理部分构造的对象,并且在抛出异常后进行
清理。


我以为这个规则已经广泛使用,应该是任何关于C ++的现代书籍的一部分。
I right now reading this book.
And he is iterating some points I''m following since 1996, e.g.
exception safety.
But e.g. he is missing one of the major exception safety guidelines,
which is

Allocate only a single resource inside a constructor body (deallocate
in the matching destructor body).
Chain such classes into base-class/member-class relationships.
This way you are able to exploit the code generation features of the
compiler,
since you wont have to deal with partially constructed objects and
cleanup after an exception has been thrown.

I was thinking that this rule is already in broad usage and should be
part of any modern book on C++.



有效的C ++并不是现代的一本书,10年后根据亚马逊的价格来源。


你的批评是有效的我猜,但是有效的C ++是一本初学者书,

和异常安全是一个高级主题。


它仍然是一本非常好的书,教会了我更多关于C ++的知识。我还读过其他单书吗?


john

Effective C++ is not that modern a book is it, 10 years old according to
Amazon.

Your criticism is valid I guess, but Effective C++ is a beginners book,
and exception safety is an advanced topic.

It remains an exceptionally good book, taught me more about C++ than any
other single book I''ve read.

john




Peter写道:

Peter wrote:

我以为这个规则已经广泛使用,应该是

现代的一部分关于C ++的书。
I was thinking that this rule is already in broad usage and should be
part of any modern book on C++.



和第138页他按构造函数调用的顺序犯了错误。

正确的顺序是:


bm1 :: constructor()

bm2 :: constructor()

Base :: Base()

dm1: :constructor()

dm2 :: constructor()

dm3 :: constructor()

派生::派生()


如果发生异常,我省略了析构函数调用的顺序。

但这很简单,因为它的顺序相反。


这个错误造成的伤害比书中的好。


and on page 138 he made a mistake in the order of constructor calls.
The correct order is:

bm1::constructor()
bm2::constructor()
Base::Base()
dm1::constructor()
dm2::constructor()
dm3::constructor()
Derived::Derived()

I left out the order of destructor calls in case of an exception.
But this is simple, as it is in reverse order.

This mistake did more damage than the book did good.


2月23日晚上11:38,彼得 < pet ... @ xpedion.comwrote:
On Feb 23, 11:38 pm, "Peter" <pet...@xpedion.comwrote:

我现在正在读这本书。

他正在迭代一些点我'自1996年以来一直关注,例如

异常安全。

但是,例如他错过了一个主要的例外安全指南,


I right now reading this book.
And he is iterating some points I''m following since 1996, e.g.
exception safety.
But e.g. he is missing one of the major exception safety guidelines,
which is



....

....


我以为这个规则已经广泛使用,应该是任何关于C ++的现代书籍的一部分。
I was thinking that this rule is already in broad usage and should be
part of any modern book on C++.



你的积分有效,但不要忘记那本书的年龄(现代

在这里无效, IMO)。写完那本书之后,Meyers发布了

有效的STL,并且是第3版的更有效的C ++。不是

*所有*都可以进入一本书。 :)


PS:我是Scott Meyers的最大粉丝。 :)

Your points are valid, but don''t forget how old that book is ("modern"
is not valid here, IMO). After writing that book Meyers released
Effective STL and is on the 3rd edition of More Effective C++. Not
*everything* could go into one book. :)

PS: i''m Scott Meyers'' biggest fan. :)


这篇关于Scott Meyers的有效C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆