Skip to content

Commit ba51efa

Browse files
committed
update
Signed-off-by: YdrMaster <[email protected]>
1 parent 1e0c19a commit ba51efa

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Diff for: exercises/12_class_destruct/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../exercise.h"
22

33
// READ: 析构函数 <https://zh.cppreference.com/w/cpp/language/destructor>
4+
// READ: RAII <https://learn.microsoft.com/zh-cn/cpp/cpp/object-lifetime-and-resource-management-modern-cpp?view=msvc-170>
45

56
/// @brief 任意缓存容量的斐波那契类型。
67
/// @details 可以在构造时传入缓存容量,因此需要动态分配缓存空间。

Diff for: exercises/13_class_clone/main.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "../exercise.h"
22

33
// READ: 复制构造函数 <https://zh.cppreference.com/w/cpp/language/copy_constructor>
4+
// READ: 函数定义(显式弃置)<https://zh.cppreference.com/w/cpp/language/function>
5+
46

57
class DynFibonacci {
68
size_t *cache;
@@ -11,7 +13,7 @@ class DynFibonacci {
1113
DynFibonacci(int capacity): cache(new ?), cached(?) {}
1214

1315
// TODO: 实现复制构造器
14-
DynFibonacci(DynFibonacci const &other) = delete;
16+
DynFibonacci(DynFibonacci const &) = delete;
1517

1618
// TODO: 实现析构器,释放缓存空间
1719
~DynFibonacci();

Diff for: exercises/14_class_move/main.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "../exercise.h"
22

3+
// READ: 左值右值(概念)<https://learn.microsoft.com/zh-cn/cpp/c-language/l-value-and-r-value-expressions?view=msvc-170>
4+
// READ: 左值右值(细节)<https://zh.cppreference.com/w/cpp/language/value_category>
5+
// READ: 关于移动语义 <https://learn.microsoft.com/zh-cn/cpp/cpp/rvalue-reference-declarator-amp-amp?view=msvc-170#move-semantics>
6+
// READ: 如果实现移动构造 <https://learn.microsoft.com/zh-cn/cpp/cpp/move-constructors-and-move-assignment-operators-cpp?view=msvc-170>
7+
38
// READ: 移动构造函数 <https://zh.cppreference.com/w/cpp/language/move_constructor>
49
// READ: 移动赋值 <https://zh.cppreference.com/w/cpp/language/move_assignment>
510
// READ: 运算符重载 <https://zh.cppreference.com/w/cpp/language/operators>
@@ -13,11 +18,11 @@ class DynFibonacci {
1318
DynFibonacci(int capacity): cache(new ?), cached(?) {}
1419

1520
// TODO: 实现移动构造器
16-
DynFibonacci(DynFibonacci &&other) noexcept = delete;
21+
DynFibonacci(DynFibonacci &&) noexcept = delete;
1722

1823
// TODO: 实现移动赋值
1924
// NOTICE: ⚠ 注意移动到自身问题 ⚠
20-
DynFibonacci &operator=(DynFibonacci &&other) noexcept = delete;
25+
DynFibonacci &operator=(DynFibonacci &&) noexcept = delete;
2126

2227
// TODO: 实现析构器,释放缓存空间
2328
~DynFibonacci();
@@ -30,6 +35,12 @@ class DynFibonacci {
3035
return cache[i];
3136
}
3237

38+
// NOTICE: 不要修改这个方法
39+
size_t operator[](int i) const {
40+
ASSERT(i <= cached, "i out of range");
41+
return cache[i];
42+
}
43+
3344
// NOTICE: 不要修改这个方法
3445
bool is_alive() const {
3546
return cache;

Diff for: exercises/15_class_derive/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int main(int argc, char **argv) {
5959
// 这是不可能的,A 无法提供 B 增加的成员变量的值
6060
// B ba = A(4);
6161

62-
// 这也是不可能的,因为 A 是 B 的一部分,就好像不可以把套娃🪆的外层放进内层里
62+
// 这也是不可能的,因为 A 是 B 的一部分,就好像不可以把套娃的外层放进内层里
6363
A ab = B(5);// 然而这个代码可以编译和运行!
6464
// THINK: 观察打印出的信息,推测把大象放进冰箱分几步?
6565
// THINK: 这样的代码是“安全”的吗?

0 commit comments

Comments
 (0)