質問編集履歴
2
追記修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -89,9 +89,7 @@
|
|
89
89
|
|
90
90
|
int main()
|
91
91
|
{
|
92
|
-
str str_exist;
|
93
|
-
|
94
|
-
for (auto e :
|
92
|
+
for (auto e : str().get_vec())
|
95
93
|
{
|
96
94
|
cout << e << endl;
|
97
95
|
}
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,4 +62,39 @@
|
|
62
62
|
}
|
63
63
|
```
|
64
64
|
|
65
|
-
2つ目のrange-based forは危険でしょうか?
|
65
|
+
2つ目のrange-based forは危険でしょうか?
|
66
|
+
|
67
|
+
【追記】
|
68
|
+
```cpp
|
69
|
+
|
70
|
+
#include <iostream>
|
71
|
+
#include <fstream>
|
72
|
+
#include <string>
|
73
|
+
#include <vector>
|
74
|
+
|
75
|
+
using namespace std;
|
76
|
+
|
77
|
+
|
78
|
+
struct str
|
79
|
+
{
|
80
|
+
vector<int> _vec
|
81
|
+
{
|
82
|
+
0,
|
83
|
+
1,
|
84
|
+
2
|
85
|
+
};
|
86
|
+
public:
|
87
|
+
auto& get_vec() { return _vec; }
|
88
|
+
};
|
89
|
+
|
90
|
+
int main()
|
91
|
+
{
|
92
|
+
str str_exist;
|
93
|
+
|
94
|
+
for (auto e : str_exist.get_vec())
|
95
|
+
{
|
96
|
+
cout << e << endl;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
```
|
100
|
+
上記なら危険なのですね。
|