Skip to content

Commit

Permalink
2023-12-07
Browse files Browse the repository at this point in the history
  • Loading branch information
XieYHccc committed Dec 8, 2023
1 parent 22d8ead commit a0925f2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _posts/2023-12-07-Copy-And-Move-Semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
## 心得

* 只有class type才有拷贝构造函数、拷贝赋值运算符、移动构造函数、移动赋值运算符。C array和Scalar type不管是在拷贝语义还是移动语义里其实都只是在做赋值/拷贝,我们可以把他们当做一块内存来看待,不用附加过多语义,而对于一块内存,就只有赋值/拷贝的概念。我们在声明一个C array或者 Scalar type时必须显示赋值/拷贝,否则内存上的值是无法预测的。

* 将一个类和它的的class type 成员递归展开,如果没有指针/资源,则移动语义没有意义,移动构造函数等价于拷贝构造函数,移动赋值函数等于移动赋值函数。

* 栈中数据的内存大小和位置是固定的,位置是相对于栈起始位置的偏移,因此 std::array<int, 5> a = std::move(b)没有意义,并不会把a变量改成b的地址和大小。(我之前竟然有这个想法...真是太蠢了)

0 comments on commit a0925f2

Please sign in to comment.