Is it possible to return std::vector as auto? For example:
auto retVec() {
std::vector<int> vec_l;
l.push_back(1);
l.push_back(2);
return vec_l;
}
...
auto ret_vec = retVec();
for (auto& it : ret_vec) {
}
when I write something like this I get an error:
- error: use of
auto retVec()before deduction ofauto--->auto ret_vec = retVec(**)**; - error: unable to deduce
auto&&fromret_vec--->for (auto it : **ret_vec**) {
How do I actually write this?
UPDATE: I'm sorry. I use this retVec as method in class and it doesn't work. When I use it as function in class - everything work fine. My mistake in formulating the question.