Skip to content

Commit 07df6ff

Browse files
committed
update
1 parent 07651ff commit 07df6ff

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

code/cpp/面向对象-不通过继承实现多态-动态序列.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ class num_sequence {
2525
cerr << "invalid sequence type\n";
2626
}
2727
}
28+
2829
void print(int n) {
2930
(this->*_pmf)(n); // 通过指针选择需要调用的函数
3031
}
32+
3133
// _pmf 可以指向以下任何一个函数
3234
void fibonacci(int n) {
3335
int f = 1;
@@ -36,6 +38,7 @@ class num_sequence {
3638
g = g + f, f = g - f;
3739
cout << f << endl;
3840
}
41+
3942
void square(int n) {
4043
cout << n * n << endl;
4144
}

编程语言/Cpp-面向对象编程.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ Index
5050
cerr << "invalid sequence type\n";
5151
}
5252
}
53+
5354
void print(int n) {
5455
(this->*_pmf)(n); // 通过指针选择需要调用的函数
5556
}
57+
5658
// _pmf 可以指向以下任何一个函数
5759
void fibonacci(int n) {
5860
int f = 1;
@@ -61,14 +63,15 @@ Index
6163
g = g + f, f = g - f;
6264
cout << f << endl;
6365
}
66+
6467
void square(int n) {
6568
cout << n * n << endl;
6669
}
6770

6871
private:
6972
PtrType _pmf;
7073
static PtrType func_tbl[cnt_seq]; // 保存所有序列函数的指针
71-
// 为了兼容性,不推荐写成 `static vector<vector<int>没有空格> _seq;`
74+
// 为了兼容性,不推荐写成 `static vector<vector<int>没有空格> _seq;`
7275
};
7376

7477
// static 成员变量初始化

0 commit comments

Comments
 (0)