book: add text about auto as func args

Fixes #180
This commit is contained in:
Changkun Ou
2021-08-11 11:20:57 +02:00
parent 7eeaa7ae4e
commit d472ff1421
3 changed files with 40 additions and 35 deletions

View File

@@ -21,10 +21,9 @@ public:
}
};
// wrong
// int add(auto x, auto y) {
// return x+y;
// }
int add(auto x, auto y) { // Supported in C++20
return x+y;
}
int main() {
MagicFoo magicFoo = {1, 2, 3, 4, 5};
@@ -34,10 +33,11 @@ int main() {
}
std::cout << std::endl;
auto i = 5; // type int
auto j = 6; // type int
auto arr = new auto(10); // type int*
// auto auto_arr2[10] = {arr};
// std::cout << add(i, j) << std::endl;
auto i = 5; // type int
auto j = 6; // type int
std::cout << add(i, j) << std::endl;
auto arr = new auto(10); // type int*
// auto auto_arr2[10] = {arr}; // invalid
return 0;
}