摘要: 1.noncopyable用于禁止复制和拷贝的类继承。声明拷贝和赋值函数为私有,将运行时的错误转化为编译期的错误。#include #include using namespace std;using namespace boost;class Mynoncopy {public: Mynoncopy(){}private: Mynoncopy(const Mynoncopy&); void operator=(const Mynoncopy&);};class Test:Mynoncopy{};int main(){ Test t1; //Test t2 = t1;//禁止拷 阅读全文
posted @ 2013-08-15 23:17 l851654152 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 讲到内存池我们会想到对对象进行动态分配的过程new包含三个过程1.使用operator new分配内存2.使用placement new 初始化3.返回内存地址。分配内存可以分解成分配内存和获取内存两步,只是一般在一步里进行。一.使用pool类,获取已经分配了的内存#include #include using namespace std;using namespace boost;int main(){ pool p1(sizeof(int)); int *p = (int*)p1.malloc();//返回内存 if (p1.is_from(p) == true) { cout #... 阅读全文
posted @ 2013-08-15 23:08 l851654152 阅读(944) 评论(0) 推荐(0) 编辑
摘要: 内存问题永远是c++中讨论的重要话题1.c98 auto_ptr的实现,auto_ptr的特点是始终只保持一个指针指向对象,若经过赋值或者拷贝之后原指针失效#include using namespace std;templateclass auto_ptr{public: explicit auto_ptr(T* px = 0):m_px(px){} auto_ptr(const auto_ptr& rhs):m_px(rhs.release()) { } auto_ptr& operator=(auto_ptr& rhs) { reset(rhs.release() 阅读全文
posted @ 2013-08-15 13:08 l851654152 阅读(290) 评论(0) 推荐(0) 编辑
摘要: date_time库使用的日期基于格里高利历,支持从1400-01-01到9999-12-31的日期。空的构造函数会创建一个值为not_a_date_time的无效日期;顺序传入年月日值则创建一个对应日期的date对象。#include #define BOOST_DATE_TIME_SOURCE#include using namespace boost::gregorian;using namespace std;using namespace boost;int main(){ date d1;//无效的时间 date d2(2013,8,15);//输入年月日 date d3(201. 阅读全文
posted @ 2013-08-15 09:48 l851654152 阅读(652) 评论(0) 推荐(0) 编辑
摘要: C++一直缺乏对时间和日期的处理能力,一般借助于C的struct tm和time();timer包含三个类其中timer,progress_timer是计时器类,进度指示类是progress_display.1.timer类,内部封装的是std::clock,精度依赖于具体的编译器和操作系统。只能计算从声明对象到对象结束的时间。#include #include using namespace std;using namespace boost;int main(){ timer t; cout #include #include using namespace std;using names 阅读全文
posted @ 2013-08-15 09:31 l851654152 阅读(1174) 评论(0) 推荐(0) 编辑