mutable constants

I'm getting an error message on each of the getters for a class i'm writting.
The error says:
error: passing `const model::container::Item' as `this' argument of `void model::container::Item::get_fields()' discards qualifiers

my getters are each defined like this.

1
2
3
4
const int& division()const{
    get_fields();
    return division_;
}


I'm assuming the problem is that my get_fields() method has the potential to modifiy division_, but I have division declared as mutable so I would think everything should be fine. What am I missing?
get_fields() is not const if it can change a member. Therefore division isn't either and you should not declare it as such. The mutable keyword subverts the entire const system.

mutable constants

See the contradiction?
Last edited on
Either way it should still compile the way i'm doing it.

I'm doing this because I don't want do a look up on the database every time a new object is constructed. I want to wait until I know I need the data before doing the full read. At that point all the fields are set once and for all.

Well then, did you declare get_fields() as const?
that was all it was. Thank you.
Topic archived. No new replies allowed.