你走多远const?您只是const在必要时制作函数,还是全力以赴,并在各处使用它?例如,假设有一个简单的变量,它带有一个布尔值: void SetValue(const bool b) { my_val_ = b; } 这const真的有用吗?我个人选择广泛使用它,包括参数,但是在这种情况下,我想知道它是否值得? 我也惊讶地发现您可以省略const函数声明中的参数,但可以将其包括在函数定义中,例如: .h文件 void func(int n, long l); .cpp文件 void func(const int n, const long l) 是否有一个原因?对我来说似乎有点不寻常。
我正在尝试检查字典是否为空,但是行为不正常。它只是跳过它并显示“ 联机”,除了显示消息外没有任何其他内容。有什么主意吗? def isEmpty(self, dictionary): for element in dictionary: if element: return True return False def onMessage(self, socket, message): if self.isEmpty(self.users) == False: socket.send("Nobody is online, please use REGISTER command" \ " in order to register into the server") else: socket.send("ONLINE " + ' ' .join(self.users.keys()))