File tree Expand file tree Collapse file tree 5 files changed +21
-4
lines changed Expand file tree Collapse file tree 5 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 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 可以在构造时传入缓存容量,因此需要动态分配缓存空间。
Original file line number Diff line number Diff line change 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
57class 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 ();
Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff 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: 这样的代码是“安全”的吗?
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ int main(int argc, char **argv) {
1010 ASSERT (vec[0 ], " Make this assertion pass." );
1111 ASSERT (vec[99 ], " Make this assertion pass." );
1212 ASSERT (vec.size () == 100 , " Make this assertion pass." );
13+ // NOTICE: 平台相关!注意 CI:Ubuntu 上的值。
14+ std::cout << " sizeof(std::vector<bool>) = " << sizeof (std::vector<bool >) << std::endl;
1315 ASSERT (sizeof (vec) == ?, " Fill in the correct value." );
1416 {
1517 vec[20 ] = false ;
@@ -25,6 +27,7 @@ int main(int argc, char **argv) {
2527 ASSERT (?ref, " Fill in `ref` or `!ref`" );
2628 ref = false ;
2729 ASSERT (?ref, " Fill in `ref` or `!ref`" );
30+ // THINK: WHAT and WHY?
2831 ASSERT (?vec[30 ], " Fill in `vec[30]` or `!vec[30]`." );
2932 }
3033 return 0 ;
You can’t perform that action at this time.
0 commit comments