@@ -252,7 +252,7 @@ int main() {
252
252
```Cpp
253
253
public:
254
254
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);
256
256
}
257
257
258
258
magicFoo.foo({6,7,8,9});
@@ -401,7 +401,7 @@ type z == type x
401
401
``` cpp
402
402
template <typename R, typename T, typename U>
403
403
R add (T x, U y) {
404
- return x+y
404
+ return x+y
405
405
}
406
406
```
407
407
> 注意: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) {
703
703
printf(args...);
704
704
}
705
705
int main() {
706
- printf(1, 2, "123", 1.1);
707
- return 0;
706
+ printf(1, 2, "123", 1.1);
707
+ return 0;
708
708
}
709
709
```
710
710
@@ -826,8 +826,8 @@ int main() {
826
826
```cpp
827
827
struct Base {
828
828
virtual void foo();
829
- };
830
- struct SubClass: Base {
829
+ };
830
+ struct SubClass: Base {
831
831
void foo();
832
832
};
833
833
```
@@ -842,11 +842,11 @@ C++11 引入了 `override` 和 `final` 这两个关键字来防止上述情形
842
842
843
843
``` cpp
844
844
struct Base {
845
- virtual void foo(int);
845
+ virtual void foo(int);
846
846
};
847
847
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; // 非法, 父类没有此虚函数
850
850
};
851
851
```
852
852
@@ -856,7 +856,7 @@ virtual void foo(float) override; // 非法, 父类没有此虚函数
856
856
857
857
```cpp
858
858
struct Base {
859
- virtual void foo() final;
859
+ virtual void foo() final;
860
860
};
861
861
struct SubClass1 final: Base {
862
862
}; // 合法
@@ -865,7 +865,7 @@ struct SubClass2 : SubClass1 {
865
865
}; // 非法, SubClass1 已 final
866
866
867
867
struct SubClass3: Base {
868
- void foo(); // 非法, foo 已 final
868
+ void foo(); // 非法, foo 已 final
869
869
};
870
870
```
871
871
@@ -881,7 +881,7 @@ C++11 提供了上述需求的解决方案,允许显式的声明采用或拒
881
881
882
882
``` cpp
883
883
class Magic {
884
- public:
884
+ public:
885
885
Magic() = default; // 显式声明使用编译器生成的构造
886
886
Magic& operator=(const Magic&) = delete; // 显式声明拒绝编译器生成构造
887
887
Magic(int magic_number);
0 commit comments