Skip to content

Commit

Permalink
Update 07-Reunderstand.C++.ShallowCopy.and.DeepCopy.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rongweihe committed Apr 20, 2019
1 parent b639a9c commit 43ce6dd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions 07-Reunderstand.C++.ShallowCopy.and.DeepCopy.md
Expand Up @@ -144,12 +144,12 @@ int main()

运行结果

> obj1.getC()=1
> obj2.getC()=1
> 调用析构函数
> ~c=0
> 调用析构函数
> ~c=-1
- obj1.getC()=1
- obj2.getC()=1
- 调用析构函数
- ~c=0
- 调用析构函数
- ~c=-1

注意到,计数器变为负数了,这是为什么呢?

Expand Down Expand Up @@ -192,18 +192,18 @@ int Base::c = 0;

运行结果

> obj11.getC()=1
> obj22.getC()=2
> 调用析构函数
> ~c=1
> 调用析构函数
> ~c=0
- obj11.getC()=1
- obj22.getC()=2
- 调用析构函数
- ~c=1
- 调用析构函数
- ~c=0



### <span id = "c"> 4、浅拷贝</span>

**浅拷贝**指的是在对象复制时,只是将对象中的数据成员进行简单的赋值,上面的例子都是属于浅拷贝的情况,**默认拷贝构造函数执行的也是浅拷贝**。大多情况下“浅拷贝”已经能很好地工作了,但是一旦对象存在了动态成员,那么浅拷贝就会出问题了,让我们考虑如下一段代码:
**浅拷贝:** 指的是在对象复制时,只是将对象中的数据成员进行简单的赋值,上面的例子都是属于浅拷贝的情况,**默认拷贝构造函数执行的也是浅拷贝**。大多情况下“浅拷贝”已经能很好地工作了,但是一旦对象存在了动态成员,那么浅拷贝就会出问题了,让我们考虑如下一段代码:

```c++
#include <bits/stdc++.h>
Expand Down Expand Up @@ -336,4 +336,4 @@ int main()

<br/>

<br/>
<br/>

0 comments on commit 43ce6dd

Please sign in to comment.