13.9Write a smart pointer (smart_ptr) class

template<class T>class SmartPoint{
public:
SmartPoint(T *ref){
ref_ = ref;
count_ = (unsigned int *)malloc(sizeof(unsigned int ));
*count_ = 1;
}
SmartPoint(SmartPoint<T> &sptr){
ref_ = sptr.ref_;
count_ = sptr.count_;
++(*count_);
}
SmartPoint<T>& operator =(SmartPoint<T> &sptr)
{
if(this != sptr){
ref_ = sptr.ref_;
count_ = sptr.count_;
++(*count_);
}
return *this;
}
~SmartPoint()
{
--(*count_);
if(*count_ == 0)
{
delete ref_;
free(count_);
ref_ = NULL;
count_ = NULL;
} }
T getValue(){
rturn *ref_;
}
private:
T* ref_;
unsigned int *count_;
};

  

CCI_chapter 13C++的更多相关文章

  1. Oracle 13c OEM 安装手册

    1       安装准备工作 以下包已Redhat 为准,其他版的操作系统以官方手册为准. 1.1         Oracle Management Service 依赖如下包 glibc-comm ...

  2. 2级搭建类EM-Oracle EMCC 13c Release 3 在 OEL 7.7 上的搭建

    Oracle Enterprise Manager Cloud Control 13c Release 3 (13.3.0.0) 安装

  3. Codeforces 13C(DP)

    题意:给出一个数列长度小于5000,每次操作将数列中的数加1或减1,问最少需要多少步操作可以得到一个不降序列: 分析:可知最少的次数,一定是由原来的数据构成的(据说可以用反证法证),即有原来的数组成的 ...

  4. Codeforces 13C Sequence --DP+离散化

    题意:给出一个 n (1 <= n <= 5000)个数的序列 .每个操作可以把 n 个数中的某一个加1 或 减 1.问使这个序列变成非递减的操作数最少是多少 解法:定义dp[i][j]为 ...

  5. Codeforces 13C Sequence

    http://codeforces.com/contest/13/problem/C 题目大意 给定一个含有N个数的序列,要求你对一些数减掉或者加上某个值,使得序列变为非递减的,问你加减的值的总和最少 ...

  6. CCI_chapter 19 Moderate

    19 1  Write a function to swap a number in place without temporary variables void swap(int &a, i ...

  7. CCI_chapter 16 Low level

    16.5 Write a program to find whether a machine is big endian or little endian Big-Endian和Little-Endi ...

  8. CCI_chapter 8 Recurision

    8.1 水题 8.2 Imagine a robot sitting on the upper left hand corner of an NxN grid The robot can only m ...

  9. CCI_chapter 4 trees and Grapths

    4.1Implement a function to check if a tree is balanced For the purposes of this question,a balanced ...

随机推荐

  1. ASCII码表(0 - 255)

    目前计算机中用得最广泛的字符集及其编码,是由美国国家标准局(ANSI)制定的ASCII码(American Standard Code for Information Interchange,美国标准 ...

  2. 程序设计实习MOOC / 继承和派生——编程作业 第五周程序填空题1

    描述 写一个MyString 类,使得下面程序的输出结果是: 1. abcd-efgh-abcd- 2. abcd- 3. 4. abcd-efgh- 5. efgh- 6. c 7. abcd- 8 ...

  3. D - Network - poj3694(LCA求桥)

    题意:有一个网络有一些边相互连接,现在有Q次操作,求每次操作后的桥的个数 分析:开始竟然不知道还有LCA这么个东西....... *********************************** ...

  4. paip.输入法编程---增加码表类型

    paip.输入法编程---增加码表类型 作者Attilax ,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attil ...

  5. 一维DFT

    学习DIP第3天 傅里叶变换是一个非常大的话题.今天实现了下一维的DFT,兴许将完毕其它傅里叶系的算法实现和实验. DFT公式:                             当中e 是自然 ...

  6. MySQL与mabits大小比较、日期比较示例

    首先,使用mysql查询从今往后的60天数据 SELECT count(*), b1.record_date FROM nk_house_use_record AS b1, ( SELECT a.th ...

  7. linux查看文件大小df-du

    1.  显示目前所有文件系统的可用空间及使用情形,h表示使用 GB.MB 等易读的格式 [root@rusky ldap]# df -hFilesystem Size Used Avail Use% ...

  8. hdu 1042

    貌似之前也写过这个题目的解题报告...老了,记性不好 从贴一遍吧! 代码理解很容易 AC代码: #include <iostream> #include <stdio.h> # ...

  9. Angular.js中的$injector服务

    一 .angular中的依赖注入 angular的一个很重要的特性就是依赖注入,可以分开理解这4个字. 1.依赖: angular里面的依赖,有angular默认提供的,也有我们自己添加的.默认提供的 ...

  10. excel运行最多行数

    2003及以前版本为65536(即6万多)行,256列2007版:1048576(即1百零多万)行,16384(即1千多)列