Transitive Const in OO programming
Alex Burton
alexibu at mac.com
Wed Aug 8 21:18:45 PDT 2007
Sean Kelly Wrote:
> Alex Burton wrote:
> > Regan Heath Wrote:
> >
> >> It seems making StateMachineWrapper::getResult non-const solves the problem.
> >
> > Yes it would but then I can't simply call a get method (getResult) using a const reference to StateMachineWrapper.
>
> Because getResult modifies the state of the object? Given this
> particular use case, I think I'd want to be aware of the 'destructive'
> behavior of getResult. I have found uses for 'mutable' in the past, but
> mostly for things like mutexes for synchronizing data access rather than
> the data itself.
>
I don't use c++ mutable either, except sometimes in tests.
The key thing here is that I am not 'modifying the state of the object', I am modifying the state of another object I just happen to be maintaining a reference to.
There is nothing to say that StateMachine is part of StateMachineWrapper.
Alex
More information about the Digitalmars-d
mailing list