Skip to content

Commit 8b47f1f

Browse files
authored
Update 02-usability.md
调整代码格式
1 parent 6411c5c commit 8b47f1f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

book/zh-cn/02-usability.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int main() {
252252
```Cpp
253253
public:
254254
void foo(std::initializer_list<int> list) {
255-
for (std::initializer_list<int>::iterator it = list.begin(); it != list.end(); ++it) vec.push_back(*it);
255+
for (std::initializer_list<int>::iterator it = list.begin(); it != list.end(); ++it) vec.push_back(*it);
256256
}
257257
258258
magicFoo.foo({6,7,8,9});
@@ -401,7 +401,7 @@ type z == type x
401401
```cpp
402402
template<typename R, typename T, typename U>
403403
R add(T x, U y) {
404-
return x+y
404+
return x+y
405405
}
406406
```
407407
> 注意:typename 和 class 在模板参数列表中没有区别,在 typename 这个关键字出现之前,都是使用 class 来定义模板参数的。但在模板中定义有[嵌套依赖类型](http://en.cppreference.com/w/cpp/language/dependent_name#The_typename_disambiguator_for_dependent_names)的变量时,需要用 typename 消除歧义
@@ -703,8 +703,8 @@ void printf(T value, Args... args) {
703703
printf(args...);
704704
}
705705
int main() {
706-
printf(1, 2, "123", 1.1);
707-
return 0;
706+
printf(1, 2, "123", 1.1);
707+
return 0;
708708
}
709709
```
710710

@@ -826,8 +826,8 @@ int main() {
826826
```cpp
827827
struct Base {
828828
virtual void foo();
829-
};
830-
struct SubClass: Base {
829+
};
830+
struct SubClass: Base {
831831
void foo();
832832
};
833833
```
@@ -842,11 +842,11 @@ C++11 引入了 `override` 和 `final` 这两个关键字来防止上述情形
842842

843843
```cpp
844844
struct Base {
845-
virtual void foo(int);
845+
virtual void foo(int);
846846
};
847847
struct SubClass: Base {
848-
virtual void foo(int) override; // 合法
849-
virtual void foo(float) override; // 非法, 父类没有此虚函数
848+
virtual void foo(int) override; // 合法
849+
virtual void foo(float) override; // 非法, 父类没有此虚函数
850850
};
851851
```
852852
@@ -856,7 +856,7 @@ virtual void foo(float) override; // 非法, 父类没有此虚函数
856856
857857
```cpp
858858
struct Base {
859-
virtual void foo() final;
859+
virtual void foo() final;
860860
};
861861
struct SubClass1 final: Base {
862862
}; // 合法
@@ -865,7 +865,7 @@ struct SubClass2 : SubClass1 {
865865
}; // 非法, SubClass1 已 final
866866
867867
struct SubClass3: Base {
868-
void foo(); // 非法, foo 已 final
868+
void foo(); // 非法, foo 已 final
869869
};
870870
```
871871

@@ -881,7 +881,7 @@ C++11 提供了上述需求的解决方案,允许显式的声明采用或拒
881881

882882
```cpp
883883
class Magic {
884-
public:
884+
public:
885885
Magic() = default; // 显式声明使用编译器生成的构造
886886
Magic& operator=(const Magic&) = delete; // 显式声明拒绝编译器生成构造
887887
Magic(int magic_number);

0 commit comments

Comments
 (0)