随笔分类 - boost
摘要:func = bind(&ResourceManager::GetExecutorResourceInfo, this, _1, info); VMPoolI::Instance()->MapToDo(func); LOG4CPLUS_DEBUG(logger, "in GetMachineInfo vm num:" << info.vm_list.size());也就是我MapToDo想把所有的虚拟机信息全部放入info的vm_list中去,在下面的函数中,的确是push进去了,但是回来之后vm_list.size就为0了,这个引用没有起到应用的
阅读全文
摘要:实例代码:// test1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <string.h>#include <string>#include <memory>#include <list>#include <iostream>using namespace std;using namespace std::tr1;class CInt: public enable_shared_fr
阅读全文
摘要:1.空的智能指针 假设如此定义typedef shared_ptr<int> IPtr; 返回为空可以设计为 IPtr f() { return IPtr(); } 测试是否为空,一般可以使用get() 返回其包裹的原指针测试是否为空,在上面的设计中,也可以直接看 IPtr i_p = f(),用!i_p来判断是否为空2. 类中也可以如此获得指向自己的智能指针 IPtr(this)
阅读全文
摘要:转载自:http://qz.qq.com/4439401/blog?uin=4439401&vin=0&blogid=1335593811条款1:不要把一个原生指针给多个shared_ptr管理int* ptr = new int;shared_ptr<int> p1(ptr);shared_ptr<int> p2(ptr); //logic errorptr对象被删除了2次这种问题比喻成“二龙治水”,在原生指针中也同样可能发生。条款2:不要把this指针给shared_ptrclass Test{public:void Do(){ m_sp = sha
阅读全文