When and object of type B
is const, then all of its members are const, which means its two members are, for the duration of B::go()
, effectively
A const a;
A * const aPtr;
The first is a constant object of type A
, on which you can only call const member functions. The second, however, is a constant pointer to a non-constant A
. You could not legally say aPtr = <anything>
from within the function B::go()
, since that would modify aPtr
, which is constant.
A pointer to a constant A
would be declared as A const* aPtr
or const A* aPtr
, which would then make calling the non-constant A::nonconst()
illegal.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…