Iterating over list of objects. #2243
-
Hi I have been trying to iterate over a list of objects using this library in a cpp file. Structure is like this :
So for this my code would go like : I thought I could use iterator for an object as well but I am facing an error for inner "for loop" which says Could anyone tell me where I am doing wrong. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
This example doesn't seem to be shown in documentation as well. I'd like documentation to explain with examples with most use cases. Would help new developers to use this library. |
Beta Was this translation helpful? Give feedback.
-
The error message is not too much related to the library, but you could have the same issue if you would iterate a Note you can simplify your code with range for (i.e., using |
Beta Was this translation helpful? Give feedback.
The error message is not too much related to the library, but you could have the same issue if you would iterate a
std::vector<std::vector<int>>
: iterators need to be dereferenced to access the underlying value. So instead oflistObject.begin()
, trylistObject->begin()
.Note you can simplify your code with range for (i.e., using
for (auto& val: list)
) anditems()
.