Should member functions be “const” if they affect logical state, but not bitwise state?

后端 未结 4 1332
一个人的身影
一个人的身影 2020-12-19 03:46

I\'m writing a class that wraps a legacy C API that controls a hardware device. In a simplified example, I might have something like:

class device
{
public:         


        
4条回答
  •  一整个雨季
    2020-12-19 04:44

    If it changes the state, it generally should not be const. The fact that the state in question is owned remotely (i.e., in a controlled device) doesn't change that.

提交回复
热议问题