I have this code and it doesn't compiled. It has an error
cannot assign to variable 'value' with const-qualified type 'const int &' value = 5;
#include <vector>
#include <set>
int main() {
std::vector<std::set<int>> data;
for (auto it = data.begin(); it != data.end(); ++it) {
auto& inner = *it;
for (auto& value: inner) {
value = 5;
}
}
return 0;
}
I thought inner
is std::set<int>&
and value
would be int&
in this case. Could someone explain this case? Thanks
Aucun commentaire:
Enregistrer un commentaire