When I can, and when I can not call variable mutable?
It is very clear with int/float/bool value.
But what about, let's say, array. Can I call native array mutable
, if I gonna add elements to it? Same with std::vector
.
One more example. I have object A, which keeps reference (B &b) to another object B. Object B have native array which I will reallocate/ std::vector (which I think is similar in this particular case ). Pseudo-code:
struct B{
std::vector<int> arr;
// int *arr; //Or this
void changeArr(){
arr.push_back(90);
}
}
struct A{
A(B &b) : b(b){};
mutable B &b; // is it ok to have it "mutable"?
//mutable B b; // or even this?
void fire() const{
b.arr.push_back(125);
// Or
b.changeArr();
}
}
Can I call B &b
mutable?
UPDATE
According to http://en.cppreference.com/w/cpp/language/cv:
mutable - defines that a member of a class does not affect the externally visible state of the class.
What is this externally visible state of the class
? Do I change it when I increase array size, reallocate something? If no, when it changes at all?