The problem is that the const method does all const member variables. In this case, however, it makes a const pointer. In particular, it's as if all you have is B * const b , which means a constant pointer to a (still) mutable B If you do not declare a member variable as const B * b (i.e., a mutable pointer to constant B ), then there is no way to protect this behavior.
If you only need const B , then be sure to specify A as follows:
class A { public: A() : b(new B) {}
However, if the other methods are A mutate B , then all you can do is make sure that B does not have a mutation in your const A methods.
rwols source share