CCI_chapter 13C++
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++的更多相关文章
- Oracle 13c OEM 安装手册
1 安装准备工作 以下包已Redhat 为准,其他版的操作系统以官方手册为准. 1.1 Oracle Management Service 依赖如下包 glibc-comm ...
- 2级搭建类EM-Oracle EMCC 13c Release 3 在 OEL 7.7 上的搭建
Oracle Enterprise Manager Cloud Control 13c Release 3 (13.3.0.0) 安装
- Codeforces 13C(DP)
题意:给出一个数列长度小于5000,每次操作将数列中的数加1或减1,问最少需要多少步操作可以得到一个不降序列: 分析:可知最少的次数,一定是由原来的数据构成的(据说可以用反证法证),即有原来的数组成的 ...
- Codeforces 13C Sequence --DP+离散化
题意:给出一个 n (1 <= n <= 5000)个数的序列 .每个操作可以把 n 个数中的某一个加1 或 减 1.问使这个序列变成非递减的操作数最少是多少 解法:定义dp[i][j]为 ...
- Codeforces 13C Sequence
http://codeforces.com/contest/13/problem/C 题目大意 给定一个含有N个数的序列,要求你对一些数减掉或者加上某个值,使得序列变为非递减的,问你加减的值的总和最少 ...
- CCI_chapter 19 Moderate
19 1 Write a function to swap a number in place without temporary variables void swap(int &a, i ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Git Bash下实现复制粘贴等快速编辑功能
在windows下使用Git Bash会经常用到选中.复制.粘贴等功能,但是一般用的方法会很复杂,笔者经过查阅一些资料,特整理一些常见编辑功能的实现方法. (1)默认方法: 单击左上角的logo ic ...
- 手机上使用asmack开发xmpp客户端
openfire服务端,smack: 下载地址:http://www.igniterealtime.org/downloads/index.jsp 源代码:http://www.ign ...
- [转]The culture name list in C#
Culture Names [C#] This example shows how to get all culture names in the .NET Framework. Use static ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...
- linux 切换用户之后变成-bash-x.x$的解决方法
我们平时在linux下切换用户后命令行为什么会变成-bash-3.2$呢,我们来分析一下,这就是跟linux的机制有关联了,因为在linux下每次通过useradd创建新的用户时,都会将所有的配置文件 ...
- JDBC批量插入数据效率分析
对于需要批量插入数据库操作JDBC有多重方式,本利从三个角度对Statement和PreparedStatement两种执行方式进行分析,总结较优的方案. 当前实现由如下条件: 执行数据库:Mysql ...
- hand第四次考核
使用Spring与Mybatis技术实现下要求: (2分)1,Spring的配置文件名称为ApplicationContext.xml (2分)2,在ApplicationContext.xml中配置 ...
- 多次绑定click及ajax提交常用方法
<script> $(document).ready(function() { //绑定click $(".exchange_ecv").bind("clic ...
- [原创+实战+钓鱼]setoolkit+映射
所需工具:setoolkit,花生壳 (此方法主要针对没有服务器,没有空间的攻击者.有服务器或者空间可以直接上传setoolkit的生成源码到服务器或者空间.) 1.setoolkit克隆一个站点 | ...
- Java基础(十)内部类
1.使用内部类的原因(3点) ①内部类方法可以访问该内部类定义所在的作用域中的数据,包括私有数据. ②内部类可以对同一个包中的其他类隐藏起来. ③当想要定义一个回调函数且不想编写大量代码时,使用匿名内 ...