Skip to content

Iterating over list of objects. #2243

Answered by nlohmann
eyepatch61 asked this question in Q&A
Discussion options

You must be logged in to vote

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 of listObject.begin(), try listObject->begin().

Note you can simplify your code with range for (i.e., using for (auto& val: list)) and items().

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@eyepatch61
Comment options

@nlohmann
Comment options

@eyepatch61
Comment options

@nlohmann
Comment options

Answer selected by eyepatch61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2243 on July 06, 2020 13:45.