可能重复:
C++ STL 集更新很乏味:我无法就地更改元素
我很难过:
struct File {
struct Handle {
size_t count;
};
std::set<Handle>::iterator handle_;
~File() {
File::close(*this);
}
static void close(File &f) {
(*f.handle_).count--;
}
};
使用ICC,错误是:
error #137: expression must be a modifiable lvalue
(*f.handle_).count++;
^
为什么 std::set::iterator 是常量?