w******0 发帖数: 43 | 1 The author in Item 11, said something about copy and assignment constructor
In following code, last line ,the author said a.data is already deleted
but I wrote a program, and did test. find the value is still there. thanks.
String a("Hello"); // define and construct a
{ // open new scope
String b("World"); // define and construct b
...
b = a; // execute default op=,
| f****4 发帖数: 1359 | 2 Effective C++ Item 11 没看到你这个例子
但是,new scope里面的string b在出scope之后delete了,而不是a | w******0 发帖数: 43 | 3 hi Brother,
Yes, It has.
Item 11: Declare a copy constructor and an assignment operator for classes
with dynamically allocated memory.
Just because b out of scope, b was deleted.
we have b = a;
so b.data point to a.data
b delete, b.data and a.data was deleted too.
so the author said a.data is already deleted
but I use cout, it can print out a.data. weird.
【在 f****4 的大作中提到】 : Effective C++ Item 11 没看到你这个例子 : 但是,new scope里面的string b在出scope之后delete了,而不是a
| z****e 发帖数: 2024 | | g**********1 发帖数: 1113 | 5 string 和 String差别很大。不要搞混了 |
|