Transitive Const in OO programming

Alex Burton alexibu at mac.com
Wed Aug 8 16:45:24 PDT 2007


Regan Heath Wrote:

> Alex Burton wrote:
> > Regan Heath Wrote:
> > 
> >> StateMachine::getResult modifies state and cannot be 'const'
> >> either.  In this case I think you need a non-const
> >> StateMachine::reset to go back to state = 0;  It makes sense,
> >> especially if you want to call getResult several times for example.
> >> 
> >> 
> >> Why call StateMachine::sendMessage inside
> >> stateMachineWrapper::getResult?
> > 
> > Because it's a state machine and thats how it works.
> > 
> >> Why does StateMachineWrapper::getResult have to be const?
> > 
> > All it does is gets a value - the fact that internally perhaps
> > several layers of code down there is a state machine should not make
> > a nice get method become non const, and in turn prevent it from being
> > used from a const method.
> > 
> >> 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.
> > 
> >> Regan
> > 
> > Thanks for your reply Regan, but I think you misunderstand my post,
> > this is not a specific programming problem I have, it is some code I
> > have constructed in order to illustrate a conceptual problem.
> 
> Correct me if I'm wrong but you want to be able to exclude parts of your 
> class from the protection given by 'const', specifically:

No what I want is to have StateMachineWrapper observe and manipulate StateMachine without StateMachine being considered part of StateMachineWrapper



More information about the Digitalmars-d mailing list