-
Notifications
You must be signed in to change notification settings - Fork 940
Expand file tree
/
Copy pathmain.cpp
More file actions
37 lines (30 loc) · 997 Bytes
/
main.cpp
File metadata and controls
37 lines (30 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "../exercise.h"
// READ: 有 cv 限定符的成员函数 <https://zh.cppreference.com/w/cpp/language/member_functions>
struct Fibonacci {
int numbers[11];
// TODO: 修改方法签名和实现,使测试通过
int get(int i) const {
return numbers[i];
}
//一定要加const修饰符 非 const 成员函数不能被 const 对象调用。
};
int main(int argc, char **argv) {
Fibonacci constexpr FIB{{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55}};
//是结构体的一种声明方式
ASSERT(FIB.get(10) == 55, "fibonacci(10) should be 55");
std::cout << "fibonacci(10) = " << FIB.get(10) << std::endl;
return 0;
}
/*
struct Point {
int x;
int y;
};
int main() {
constexpr Point p{3, 4}; // ✅ 聚合初始化
// 或者更明确一点:
constexpr Point q = {10, 20}; // ✅ 等价写法
std::cout << p.x << ", " << p.y << std::endl; // 输出: 3, 4
}
看起来也是跟python类似的结构体初始化
*/