Advertisement Jump to content


This topic is now archived and is closed to further replies.


mutable and error flags

This topic is 5778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class with a number of inspector functions, when a fail condition occurs in an inspector function, the class calls one of two private methods, reportWarning(s) and reportError(s). Both display a dialog, informing the user that an fail condition has been reached. The difference is that when certain inspectors fail, no later inspectors should be allowed to succeed. These are the methods that call reportError, which then sets a bool m_bFatalError to true. The problem is, that this means that reportError is non-const, so any inspectors that call it are non-const. One way around this is to make m_bFatalError mutable. Is this a correct usage of mutable, or is it subversive? Is it the case that inspectors that may cause a fatal error are also conceptually non-const? I read of exmaples of mutable members being things like a cache, to speed up lookups. In a way, this m_bFatalError is like a cache, caching the fact that you can''t read from this object any more.

Share this post

Link to post
Share on other sites
Yes, that''s the intended usage of mutable - modifying members of const structures. Whether or not it''s good design is debatable. I guess in this case it is, although I think const-correctness isn''t worth all that much.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!