質問編集履歴
2
追記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -180,11 +180,7 @@
|
|
180
180
|
|
181
181
|
{
|
182
182
|
|
183
|
-
str str_exist;
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
for (auto e : str
|
183
|
+
for (auto e : str().get_vec())
|
188
184
|
|
189
185
|
{
|
190
186
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,73 @@
|
|
127
127
|
|
128
128
|
|
129
129
|
2つ目のrange-based forは危険でしょうか?
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
【追記】
|
134
|
+
|
135
|
+
```cpp
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
#include <iostream>
|
140
|
+
|
141
|
+
#include <fstream>
|
142
|
+
|
143
|
+
#include <string>
|
144
|
+
|
145
|
+
#include <vector>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
using namespace std;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
struct str
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
vector<int> _vec
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
0,
|
164
|
+
|
165
|
+
1,
|
166
|
+
|
167
|
+
2
|
168
|
+
|
169
|
+
};
|
170
|
+
|
171
|
+
public:
|
172
|
+
|
173
|
+
auto& get_vec() { return _vec; }
|
174
|
+
|
175
|
+
};
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
int main()
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
str str_exist;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
for (auto e : str_exist.get_vec())
|
188
|
+
|
189
|
+
{
|
190
|
+
|
191
|
+
cout << e << endl;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
上記なら危険なのですね。
|