Skip to content

Commit d14b63b

Browse files
authored
Merge pull request #3 from Hniii98/bug_fix
[docs][cppguidebook.typ] Fix the virtual fuction's name and the use o…
2 parents a35ceb1 + 97e1e05 commit d14b63b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/functional.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ int main() {
670670
671671
```cpp
672672
struct OpBase { // 面向对象:遇事不决先定义接口……
673-
virtual int operate(int a, int b) = 0;
673+
virtual int compute(int a, int b) = 0;
674674
virtual ~OpBase() = default;
675675
};
676676

@@ -695,7 +695,7 @@ struct OpMax : OpBase {
695695
int generic_sum(std::vector<int> const &v, OpBase *op) {
696696
int ret = v[0];
697697
for (int i = 1; i < v.size(); ++i) {
698-
ret = op.compute(ret, v[i]); // 写起来也麻烦,需要调用他的成员函数,成员函数又要起名……
698+
ret = op->compute(ret, v[i]); // 写起来也麻烦,需要调用他的成员函数,成员函数又要起名……
699699
}
700700
delete op;
701701
return ret;

misc/typst/cppguidebook.typ

+2-2
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ int main() {
12751275
12761276
```cpp
12771277
struct OpBase { // 面向对象:遇事不决先定义接口……
1278-
virtual int operate(int a, int b) = 0;
1278+
virtual int compute(int a, int b) = 0;
12791279
virtual ~OpBase() = default;
12801280
};
12811281

@@ -1300,7 +1300,7 @@ struct OpMax : OpBase {
13001300
int generic_sum(std::vector<int> const &v, OpBase *op) {
13011301
int ret = v[0];
13021302
for (int i = 1; i < v.size(); ++i) {
1303-
ret = op.compute(ret, v[i]); // 写起来也麻烦,需要调用他的成员函数,成员函数又要起名……
1303+
ret = op->compute(ret, v[i]); // 写起来也麻烦,需要调用他的成员函数,成员函数又要起名……
13041304
}
13051305
delete op;
13061306
return ret;

0 commit comments

Comments
 (0)