02 2012 档案

const成员函数, const member function
摘要:起源上周在写talk的OnlineStatManager的时候(一个用于管理用户在线类型的类), 其中有个private member.private: OnlineType getStat(int userId) const ;用来读出user的在线类型, 我把这个member声明为了const , 在读map的时候加读锁, 锁用到了自己定义的类成员 boost::shared_mutex mu_; 截取相关代码如下 1 class OnlineStatManager { 2 // ... 3 private: 4 OnlineType getStat(int us... 阅读全文

posted @ 2012-02-20 18:20 小宇2 阅读(2551) 评论(0) 推荐(0) 编辑

enum 随笔
摘要:工作中的代码常看到在一个类里面定义一个 enum , 而只用这个 enum, 也许没有把它放到类中的必要, 但是不放到类中, 每一个枚举量在namespace就是直接可见的, 也不太好写了个测试小程序注意到, enum和int是一个size, 4 bytes. enum中的枚举量(常量), 在它所在的namespace中直接可见, class也是定义了一个namespace20,21行两种转换方式, 不转换是编译不过的22,23 两种定义枚举变量的方式 1 #include <iostream> 2 using namespace std; 3 4 enum Type { 5 .. 阅读全文

posted @ 2012-02-16 21:07 小宇2 阅读(329) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示