2012年5月24日

摘要: IO Stream Library : Standard Input Output Stream Library, 这是一个面向对象的库, 用流的方式提供input,output功能写了一个关于stringstream的小测试程序 1 #include<string> 2 #include<iostream> 3 #include<sstream> 4 using namespace std; 5 int main () 6 { 7 stringstream ss; 8 int i1 = 123; 9 ss << i1;10 string str 阅读全文
posted @ 2012-05-24 20:10 小宇2 阅读(599) 评论(0) 推荐(0) 编辑

2012年5月18日

摘要: 1 function object就是重载了operator()的类的对象, 像如下例子, 其实也许应该说是定义了operator()的类, 在thinking in c++中operator overloading都并没有提到operator() 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 class Wy { 5 public : 6 string operator()(string msg, int a, int b){ 7 cout << "msg = 阅读全文
posted @ 2012-05-18 12:18 小宇2 阅读(849) 评论(0) 推荐(0) 编辑

2012年5月15日

摘要: http://www.boost.org/doc/libs/1_46_1/doc/html/string_algo.html这个库是个 headers only library 这个库提供了STL没有提供的 string-related算法, 但是实现做到了可以用在任何 character 的 container上split在写在线状态的改造时候要把一个字符串中描述的几种类型拆出来, 引发了这个问题, 去标准库里找了也没找到, 后来在boost库中找到了string_algo这个库, 以下是我写的一个使用split的例子 1 #include <boost/algorithm/strin 阅读全文
posted @ 2012-05-15 15:20 小宇2 阅读(13558) 评论(0) 推荐(0) 编辑

2012年4月25日

摘要: 看了下thinking in c++ v2 中的 exception handling, 这里简单总结下C++语言层面exception handling理解1 . throw, try , catchthrow expression; 这是在程序普通地方用的, expression总是有一个类型的, 也就是说可以抛出任意一个 type 的 object;throw ; 是在 catch 语句里面使用的, 把接收到的object再次抛出, 当然在catch中也可以再抛出任意type的异常 1 #include <iostream> 2 using namespace std; 3 阅读全文
posted @ 2012-04-25 20:31 小宇2 阅读(2075) 评论(0) 推荐(0) 编辑

2012年4月20日

摘要: 当constructor, destructor为protected时, 不允许实例化这个类,不管是在栈中还是在堆中,(但可以实例化派生类(protected 的 constructor可以在派生类中调用)) , 当在栈中实例化一个类时, 需要constructor和destructor都是public的, 而在堆中new时 ,需要constructor是public的, 而当调了delete时, 才需要destructor是public的 , 当constructor为private时, 不仅不允许实例化这个类, 也实例化不了派生类(private constructor只能在本类成员中调用 阅读全文
posted @ 2012-04-20 20:40 小宇2 阅读(924) 评论(0) 推荐(0) 编辑

2012年3月31日

摘要: xmpp的官网,上面有xmpp的一切重要信息:http://xmpp.orgXMPP(Extensible Messaging and Presence Protocol), 是XML的一种应用, 用于即时的(near real time)在两个或多个网络实体(network entity)间交换 结构化的可扩展的数据(structured and extensible data),以下两个是XMPP的两个主要的协议, 第一个主要讲了如何建立和关闭一个XML stream , XML stream, XML stanza的定义, XMPP中的术语(terminology)的定义, XMPP的技 阅读全文
posted @ 2012-03-31 09:27 小宇2 阅读(703) 评论(0) 推荐(0) 编辑

2012年3月12日

摘要: http://www.boost.org/doc/libs/1_46_1/doc/html/thread/synchronization.htmlmutex 是mutual exclusion(互斥), 是一个概念 , A mutex object facilitates protection against data races and allows thread-safe synchronization of data between threads, 这句话描述了mutex object的作用, 在这篇文档中, 定义了几4种 mutex concept, 每种concept都有对应的几. 阅读全文
posted @ 2012-03-12 17:14 小宇2 阅读(951) 评论(0) 推荐(0) 编辑

2012年3月5日

摘要: shared_ptr enable_shared_from_this一种避免内存泄漏的方式是, always use a named smart pointer variable to hold the result of newshared_ptr<T> p(new T);http://hi.baidu.com/jrckkyy/blog/item/ac3e5511fa4a59caa6ef3ff1.html 这篇文章讲了shared_from_this几个值得注意的地方, 看了几次,然后去翻阅了下源码,搞明白了boost文档中首先讲了enable_shared_from_this的 阅读全文
posted @ 2012-03-05 11:20 小宇2 阅读(6242) 评论(0) 推荐(1) 编辑

2012年2月20日

摘要: 起源上周在写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 阅读(2536) 评论(0) 推荐(0) 编辑

2012年2月16日

摘要: 工作中的代码常看到在一个类里面定义一个 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 阅读(324) 评论(0) 推荐(0) 编辑

导航