Update item3.md

This commit is contained in:
猫耳堀川雷鼓 2021-03-02 11:39:14 +08:00 committed by GitHub
parent 4753623c99
commit 55885ba78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,19 +17,19 @@ struct Point{
Widget w; //decltype(w)是Widget
if (f(w))... //decltype(f(w))是bool
if (f(w))//decltype(f(w))是bool
template<typename T> //std::vector的简化版本
class vector{
public:
...
T& operator[](std::size_t index);
...
}
};
vector<int> v; //decltype(v)是vector<int>
...
if (v[0] == 0)... //decltype(v[0])是int&
if (v[0] == 0)//decltype(v[0])是int&
````
看见了吧?没有任何奇怪的东西。
@ -65,7 +65,7 @@ auto authAndAccess(Container& c, Index i) //不那么正确
````cpp
std::deque<int> d;
...
authAndAccess(d, 5) = 10; //认证用户返回d[5]
//然后把10赋值给它
//无法通过编译器!
@ -159,13 +159,13 @@ int x = 0;
decltype(auto) f1()
{
int x = 0;
...
return x; //decltype(x是int所以f1返回int
}
decltype(auto) f2()
{
int x =0l;
int x = 0;
return (x); //decltype((x))是int&所以f2返回int&
}
````