Transitive Const in OO programming
Alex Burton
alexibu at mac.com
Wed Aug 8 05:54:33 PDT 2007
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.
Alex
More information about the Digitalmars-d
mailing list