mirror of
https://github.com/CnTransGroup/EffectiveModernCppChinese.git
synced 2024-12-26 21:00:23 +08:00
Update item6.md
This commit is contained in:
parent
577760c36d
commit
caad38385d
@ -9,9 +9,9 @@ std::vector<bool> features(const Widget& w);
|
||||
更进一步假设第5个*bit*表示`Widget`是否具有高优先级,我们可以写这样的代码:
|
||||
````cpp
|
||||
Widget w;
|
||||
...
|
||||
…
|
||||
bool highPriority = features(w)[5]; //w高优先级吗?
|
||||
...
|
||||
…
|
||||
processWidget(w, highPriority); //根据它的优先级处理w
|
||||
````
|
||||
这个代码没有任何问题。它会正常工作,但是如果我们使用`auto`代替`highPriority`的显式指定类型做一些看起来很无害的改变:
|
||||
@ -74,11 +74,11 @@ namespace std{ //来自于C++标准库
|
||||
template<class Allocator>
|
||||
class vector<bool, Allocator>{
|
||||
public:
|
||||
...
|
||||
class reference { ... };
|
||||
…
|
||||
class reference { … };
|
||||
|
||||
reference operator[](size_type n);
|
||||
...
|
||||
…
|
||||
};
|
||||
}
|
||||
````
|
||||
|
Loading…
Reference in New Issue
Block a user