I want to know how mutable affects a container (map, vector, list, ...). In addition, what do I have to bear in mind?
mutable
, like const
, is just a compile-time thing. It just allows you to modify that variable in a constant context. At runtime, there is no difference wether you declared the container mutable
or not.
class Foo{
mutable int i;
public:
void foo() const{
// constant context, but you can modify `i`
i = 5;
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.