forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.37.cpp
More file actions
42 lines (31 loc) · 661 Bytes
/
Copy path6.37.cpp
File metadata and controls
42 lines (31 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <string>
using std::string;
string (&foo1())[10];
using arr_str_type = string[10];
//typedef string arr_str_type[10];
arr_str_type &foo2();
auto foo3() -> string (&)[10];
string str[10] = {};
decltype(str) &foo4();
// I prefer the trailing return form, because it's much easier to understand.
// I also prefer the type alias form, becasue it's easy to use, especially when
// the type being used many times.
string (&foo1())[10] {
return str;
}
arr_str_type &foo2() {
return str;
}
auto foo3() -> string (&)[10] {
return str;
}
decltype(str) &foo4() {
return str;
}
int main() {
foo1();
foo2();
foo3();
foo4();
return 0;
}