键盘上的舞者

My Email: marckywu@gmail.com
随笔 - 19, 文章 - 0, 评论 - 3, 引用 - 0
数据加载中……

2009年8月13日

安全访问数组的指针类模板

     摘要: 在用数组作为数据结构存储数据的时候,一不小心就访问越界了,这类错误有时候很不容易发现。为此自己封装一个专门用来访问数组元素的指针类模板。此类模板需要数组的元素类型,起始地址,大小来构造一个安全的Ptr2T指针对象,此对象访问数组的方法不但与普通的指针相同,同时还增加了越界的安全检查。  阅读全文

posted @ 2009-08-13 18:29 Marcky 阅读(336) | 评论 (0)编辑 收藏

显示构造函数与转换运算符的合作

     摘要: 在设计一个Date类的时候,我们使用int类型来表示年份,如果我们需要对年份进行一些特殊的操作(如:检查,保护等),就很需要定义一个Year类,如下:  阅读全文

posted @ 2009-08-13 14:39 Marcky 阅读(252) | 评论 (0)编辑 收藏

Allocating Arrays Using Placement new (zz)

     摘要: An additional version of operator new enables you to construct an object or an array of objects at a predetermined memory position. This version is called placement new and has many useful applications, including building a custom-made memory pool or a garbage collector. Additionally, it can be used in mission-critical applications because there's no danger of allocation failure; the memory that's used by placement new has already been allocated. Placement new is also faster because the cons  阅读全文

posted @ 2009-08-13 00:48 Marcky 阅读(326) | 评论 (0)编辑 收藏