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 ...
随机推荐
- [LeetCode] 28. Implement strStr() 解题思路
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【KMP】Period
KMP算法 Next[]函数深入理解,Next[]当前字符前匹配字符数,串长n-Next[i]=串内循环子串的长度p. 本题求子循环串内循环节数. Problem Description For ea ...
- tomcat+redis实现session共享缓存
一:linux下redis安装 1.wget http://download.redis.io/releases/redis-3.2.4.tar.gz 2.tar xzf redis-3.2.4.ta ...
- html——基础样式篇(1)
格式化标签 <b>字体加粗标签 <i>字体斜体标签 <sub>下标标签 <sup>上标标签 <del>删除标签 //这在商品特价时常使用 a ...
- javascript获取标签样式(获取背景为例)
function getStyle(el){ if(window.getComputedStyle){ return window.getComputedStyle(el,null); } retur ...
- oralce 恢复Delete删除
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; select * from db_datatable as of timestam ...
- Code First研究学习2_基本的错误及解决方法
使用Code First时总有很多的问题出现,以下列举了一些基本的错误及解决方法! 1.当用Enable-Migrations启动数据库迁移后,如果再继续输入Enable-Migrations命令,则 ...
- 深入理解REST与Servlet架构的区别
本身这个比较是个伪命题,因为 RESTful Service是一个软件架构“风格”, 而servlet是java 服务端的一种技术 之所以把它们拿出来比较,是由于它们代表了两个时代的技术风格与架构.下 ...
- C#操作EXCEL的时候出现“ 无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的COM 对象强制转换为接口类型“Microsoft.Office.Interop.Excel._Application” ”问题
总是报出这个错误,准备放弃COM的组件转投NPOI,后来想起在装这个操作系统的时候,自带装过WPS,后来使用360卸载了.于是想着试一试的心态,重新安装了WPS,结果,问题解决了.你懂的.
- JQ简单图片轮播
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...