答题程序一些mark
- 灵活使用断言来使程序更加清晰,更加容易调制BUG assert(it != users.end()),头文件<assert.h>;
- 将程序分拆,划分为各个极小的模块,从而使程序更加清晰,以后优化更加方便
- 登陆验证程序:另外配置一个session类,存储用户的登录状态.
6 class Session
7 {
8 public:
9
10 Session() :username_(""), valid_(false) { }
11
12 void setUsername(const std::string &username)
13 { username_ = username; }
14 const std::string &getUsername() const
15 { return username_; }
16
17 void makeValid()
18 { valid_ = true; }
19 bool isValid() const
20 { return valid_; }
21
22 private:
23
24 std::string username_;
25 bool valid_;
26
27 };