S****z 发帖数: 666 | 1 首先说 operator= (const Widget& rhs) //pass by ref
用引用可以省copy constructor
但是在下面一章的handle assignment to self in operator=
又说为了making operator= exception-safe
要用copy and swap技术
所以要把operato=定义为
Widget& Widget::operator=(Widget rhs) //pass by value
{
swap(rhs); //swap *this's data with the copy's
return *this;
}
一时说pass by ref一时又说pass by value
这样墙头草的书不读也罢!!
我太阳! |
p***o 发帖数: 1252 | 2 You don't get the point. He first showed you a typical textbook solution,
which is difficult to get exception safe (and most textbook writers don't
understand what is exception safe), and then showed you the copy-and-swap
idiom, which is simple and exception safe.
【在 S****z 的大作中提到】 : 首先说 operator= (const Widget& rhs) //pass by ref : 用引用可以省copy constructor : 但是在下面一章的handle assignment to self in operator= : 又说为了making operator= exception-safe : 要用copy and swap技术 : 所以要把operato=定义为 : Widget& Widget::operator=(Widget rhs) //pass by value : { : swap(rhs); //swap *this's data with the copy's : return *this;
|
S****z 发帖数: 666 | 3 原来这书作者是在BSO它自己的safe而其他书的不safe是吧
好吧,这次忍了,再往下读读看
BTW:貌似还有本叫More Effective C++?既然它叫More Effective
那More的作者应该比这个没有More的更牛叉吧,我是不是直接读那本就行了
没必要在这本没有More的上浪费时间?
【在 p***o 的大作中提到】 : You don't get the point. He first showed you a typical textbook solution, : which is difficult to get exception safe (and most textbook writers don't : understand what is exception safe), and then showed you the copy-and-swap : idiom, which is simple and exception safe.
|
S*********g 发帖数: 5298 | 4 太浪费时间了。牛人都不看书,直接自己拍脑袋整一个C++,譬如stroustrup
【在 S****z 的大作中提到】 : 原来这书作者是在BSO它自己的safe而其他书的不safe是吧 : 好吧,这次忍了,再往下读读看 : BTW:貌似还有本叫More Effective C++?既然它叫More Effective : 那More的作者应该比这个没有More的更牛叉吧,我是不是直接读那本就行了 : 没必要在这本没有More的上浪费时间?
|
b******n 发帖数: 592 | 5 所以才是个半成品。。编程语言真没有好用的。。。
【在 S*********g 的大作中提到】 : 太浪费时间了。牛人都不看书,直接自己拍脑袋整一个C++,譬如stroustrup
|
S****z 发帖数: 666 | 6 原来是这个叫stroustrup弄出来的
我对C++很不满,有他的email吗?我要complain!
【在 S*********g 的大作中提到】 : 太浪费时间了。牛人都不看书,直接自己拍脑袋整一个C++,譬如stroustrup
|
S****z 发帖数: 666 | 7 怪不得我怎么感觉那么不爽,原来是半成品
【在 b******n 的大作中提到】 : 所以才是个半成品。。编程语言真没有好用的。。。
|
t****t 发帖数: 6806 | 8 这坑太烂了, 打回重挖.
【在 S****z 的大作中提到】 : 首先说 operator= (const Widget& rhs) //pass by ref : 用引用可以省copy constructor : 但是在下面一章的handle assignment to self in operator= : 又说为了making operator= exception-safe : 要用copy and swap技术 : 所以要把operato=定义为 : Widget& Widget::operator=(Widget rhs) //pass by value : { : swap(rhs); //swap *this's data with the copy's : return *this;
|
z****e 发帖数: 2024 | 9 作者写的挺清楚的,打回去重读。
【在 S****z 的大作中提到】 : 首先说 operator= (const Widget& rhs) //pass by ref : 用引用可以省copy constructor : 但是在下面一章的handle assignment to self in operator= : 又说为了making operator= exception-safe : 要用copy and swap技术 : 所以要把operato=定义为 : Widget& Widget::operator=(Widget rhs) //pass by value : { : swap(rhs); //swap *this's data with the copy's : return *this;
|
g*******e 发帖数: 3013 | 10 Effective Java 这本书不错(看亚马逊评价)。改看这本吧。;)
【在 S****z 的大作中提到】 : 首先说 operator= (const Widget& rhs) //pass by ref : 用引用可以省copy constructor : 但是在下面一章的handle assignment to self in operator= : 又说为了making operator= exception-safe : 要用copy and swap技术 : 所以要把operato=定义为 : Widget& Widget::operator=(Widget rhs) //pass by value : { : swap(rhs); //swap *this's data with the copy's : return *this;
|
|
|
m***i 发帖数: 2480 | 11 My company C++ style guide: Neither operator overloading nor exception is
allowed.
【在 S****z 的大作中提到】 : 首先说 operator= (const Widget& rhs) //pass by ref : 用引用可以省copy constructor : 但是在下面一章的handle assignment to self in operator= : 又说为了making operator= exception-safe : 要用copy and swap技术 : 所以要把operato=定义为 : Widget& Widget::operator=(Widget rhs) //pass by value : { : swap(rhs); //swap *this's data with the copy's : return *this;
|
h***i 发帖数: 1970 | 12 听起来像是google.
【在 m***i 的大作中提到】 : My company C++ style guide: Neither operator overloading nor exception is : allowed.
|
g**w 发帖数: 969 | 13 是啊,作者说的很清楚,
swap/exception safe基本型也是pass by reference实现,
pass by value是个trick,
他也很worry看起来不好。
【在 z****e 的大作中提到】 : 作者写的挺清楚的,打回去重读。
|
b******n 发帖数: 592 | 14 how does it work without exception? I used to use a lot macros in C, but it
is far from ideal. I'd like to learn.
【在 h***i 的大作中提到】 : 听起来像是google.
|
z****e 发帖数: 2024 | 15 that's the most general tone to show a trick in academic publication.
before others start to blame the author as zhuang B-ility, himself talk in a
conservertive tone about his zhuang Bility first.
As a result, he can zhuang B and defense all blames simultaneously.
【在 g**w 的大作中提到】 : 是啊,作者说的很清楚, : swap/exception safe基本型也是pass by reference实现, : pass by value是个trick, : 他也很worry看起来不好。
|
c**b 发帖数: 2999 | 16 Widget rhs
Widget* rhs
Widget& rhs
可能书作者在炫耀他对这3个的区别很清楚.其实,写c++ 的那个人,就是为了炫耀他对内
存理解之深之透.
【在 S****z 的大作中提到】 : 首先说 operator= (const Widget& rhs) //pass by ref : 用引用可以省copy constructor : 但是在下面一章的handle assignment to self in operator= : 又说为了making operator= exception-safe : 要用copy and swap技术 : 所以要把operato=定义为 : Widget& Widget::operator=(Widget rhs) //pass by value : { : swap(rhs); //swap *this's data with the copy's : return *this;
|
c**b 发帖数: 2999 | 17 还是选本好书看吧.每本c++书讲故事的方式都不一樣,看了一本,再去看另外一本,简直
就是找不到方向.
【在 S****z 的大作中提到】 : 原来这书作者是在BSO它自己的safe而其他书的不safe是吧 : 好吧,这次忍了,再往下读读看 : BTW:貌似还有本叫More Effective C++?既然它叫More Effective : 那More的作者应该比这个没有More的更牛叉吧,我是不是直接读那本就行了 : 没必要在这本没有More的上浪费时间?
|
g**w 发帖数: 969 | 18 effective c++和c++ primer差不多
熟悉C, 看看两本里的任一本就可以了,
剩下的就是多写code
【在 c**b 的大作中提到】 : 还是选本好书看吧.每本c++书讲故事的方式都不一樣,看了一本,再去看另外一本,简直 : 就是找不到方向.
|