I\'ve been searching for the different uses of the keyword mutable. I\'ve found
ID: 655550 • Letter: I
Question
I've been searching for the different uses of the keyword mutable. I've found that it is generally used for caching, lazy computing, mutex, ...
But I'm wondering if it is coherent to use it for a cursor on a readonly object.
For example, I have a sound class, and I want each sound to be able to keep track of a play cursor, for play/pause use, but I don't think this is part of the state of the sound. A const sound cannot be modified, but it can be read.
Is it ok to make the cursor attribute mutable?
Explanation / Answer
I believe your design would be better if the cursor attribute was changed to a function that created and returned a new cursor object that referenced this sound object.
That way you can have multiple modifiable cursors referencing the same sound object, all the cursors at different positions in the sound file -> which is just how cursors should work.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.