Mythma‘s C++ blog
用5年时间来学C++.
C++博客
首页
新随笔
新文章
联系
聚合
管理
posts - 79,comments - 395,trackbacks - 0
EMail/MSN:
mythma at 126.com
Location:
Shanghai
3D Modeling Visualization
Email:
访问...
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
(20)
给我留言
查看公开留言
查看私人留言
随笔分类
(82)
ACIS/HOOPS(2)
C++ FAQ(10)
C++ Practice(15)
COM&ATL&WTL(2)
GP&STL(5)
OGRE Analysis(13)
OGRE Notes(4)
OpenCASCADE(8)
VC&MFC(11)
Venus Plan(12)
文章分类
Papers
General
博友连接
最新随笔
1. 3D Modeling&Visualization Group
2. 升级到 VS2008 SP1 注意问题
3. 屏幕截图工具V2
4. Goodbye, VC Intellisense !
5. 判断拓扑结构的具体类型
6. VC2008 Feature Pack的问题
7. VC2008 竟然不带 glaux.lib!
8. AnyCAD 2008 Preview Special Version
9. 手机号码黑名单
10. 构建通用类型- 继承 VS 聚合
11. boost::any 与 boost::variant 的区别
12. 拓扑结构与TopoDS
13. New MFC将加入BCGControlBar
14. VTK Online 教程大全
15. 用wxWidgets做界面
积分与排名
积分 - 128567
排名 - 11
最新评论
1. re: 手机号码黑名单
15914963970
--hl
2. re: 手机号码黑名单
这个是骗子。13674513309。骗你把钱邮寄到账户:工商银行:6222 0237 0000 8883 102 张丽琴
--kj
3. re: 手机号码黑名单
手机号码黑名单13750586451 .这个是纯种黑背。大家以后要注意。。。
--hn0396
4. re: 升级到 VS2008 SP1 注意问题
评论内容较长,点击标题查看
--力为
5. re: [tool]文件夹比较
能不能把界面部分的代码发过来学习一下?meibao_2000@163.com
非常感谢,先谢了!
--alexmayer
阅读排行榜
1. 用wxWidgets做界面(4968)
2. VC+ADO操作数据库注意事项(1)(3975)
3. fstream 和 中文路径(3947)
4. 升级到 VS2008 SP1 注意问题(3624)
5. 屏幕截图工具V1[附源码](3460)
评论排行榜
1. Pro OGRE 3D Programming 电子版(53)
2. 手机号码黑名单(35)
3. 屏幕截图工具V1[附源码](21)
4. 波形显示不是很难(14)
5. 用istringstream 解决问题一则(14)
6. fstream 和 中文路径(14)
7. 五个小矮人分桃子-一道小学生的作业题目(12)
8. OGRE动画练习(12)
9. VC+ADO操作数据库注意事项(1)(12)
10. OGRE粒子系统之在烈火中永生(10)
const auto_ptr保证拥有权不能转移的实现原理?
const auto_ptr保证拥有权不能转移的实现原理?
在《C++标准程序库》p55,提到了auto_ptr使用了一个技巧,能够copy和复制non-const auto_ptr,但不可以copy和复制const atuo_ptr。
可看了之后没感觉,等待高手指点中.....
CSDN领分之处:
http://community.csdn.net/Expert/topic/4347/4347660.xml?temp=.3555872
VC7的
//
VC7中的
//
TEMPLATE CLASS auto_ptr
template
<
class
_Ty
>
class
auto_ptr;
template
<
class
_Ty
>
struct
auto_ptr_ref
{
//
proxy reference for auto_ptr copying
auto_ptr_ref(auto_ptr
<
_Ty
>&
_Right)
: _Ref(_Right)
{
//
construct from compatible auto_ptr
}
auto_ptr
<
_Ty
>&
_Ref;
//
reference to constructor argument
}
;
template
<
class
_Ty
>
class
auto_ptr
{
//
wrap an object pointer to ensure destruction
public
:
typedef _Ty element_type;
explicit
auto_ptr(_Ty
*
_Ptr
=
0
) _THROW0()
: _Myptr(_Ptr)
{
//
construct from object pointer
}
auto_ptr(auto_ptr
<
_Ty
>&
_Right) _THROW0()
: _Myptr(_Right.release())
{
//
construct by assuming pointer from _Right auto_ptr
}
auto_ptr(auto_ptr_ref
<
_Ty
>
_Right) _THROW0()
: _Myptr(_Right._Ref.release())
{
//
construct by assuming pointer from _Right auto_ptr_ref
}
template
<
class
_Other
>
operator
auto_ptr
<
_Other
>
() _THROW0()
{
//
convert to compatible auto_ptr
return
(auto_ptr
<
_Other
>
(
*
this
));
}
template
<
class
_Other
>
operator
auto_ptr_ref
<
_Other
>
() _THROW0()
{
//
convert to compatible auto_ptr_ref
return
(auto_ptr_ref
<
_Other
>
(
*
this
));
}
template
<
class
_Other
>
auto_ptr
<
_Ty
>&
operator
=
(auto_ptr
<
_Other
>&
_Right) _THROW0()
{
//
assign compatible _Right (assume pointer)
reset(_Right.release());
return
(
*
this
);
}
template
<
class
_Other
>
auto_ptr(auto_ptr
<
_Other
>&
_Right) _THROW0()
: _Myptr(_Right.release())
{
//
construct by assuming pointer from _Right
}
auto_ptr
<
_Ty
>&
operator
=
(auto_ptr
<
_Ty
>&
_Right) _THROW0()
{
//
assign compatible _Right (assume pointer)
reset(_Right.release());
return
(
*
this
);
}
auto_ptr
<
_Ty
>&
operator
=
(auto_ptr_ref
<
_Ty
>&
_Right) _THROW0()
{
//
assign compatible _Right._Ref (assume pointer)
reset(_Right._Ref.release());
return
(
*
this
);
}
~
auto_ptr()
{
//
destroy the object
delete _Myptr;
}
_Ty
&
operator
*
()
const
_THROW0()
{
//
return designated value
return
(
*
_Myptr);
}
_Ty
*
operator
->
()
const
_THROW0()
{
//
return pointer to class object
return
(
&**
this
);
}
_Ty
*
get
()
const
_THROW0()
{
//
return wrapped pointer
return
(_Myptr);
}
_Ty
*
release() _THROW0()
{
//
return wrapped pointer and give up ownership
_Ty
*
_Tmp
=
_Myptr;
_Myptr
=
0
;
return
(_Tmp);
}
void
reset(_Ty
*
_Ptr
=
0
)
{
//
destroy designated object and store new pointer
if
(_Ptr
!=
_Myptr)
delete _Myptr;
_Myptr
=
_Ptr;
}
private
:
_Ty
*
_Myptr;
//
the wrapped object pointer
}
;
posted on 2005-10-24 22:07
力为
阅读(414)
评论(3)
编辑
收藏
引用
所属分类:
GP&STL
FeedBack:
#
re: const auto_ptr保证拥有权不能转移的实现原理?
2005-10-24 23:32 |
ilovevc
要不看看我写的
http://blog.csdn.net/ilovevc/archive/2005/09/09/475896.aspx
回复
更多评论
#
re: const auto_ptr保证拥有权不能转移的实现原理?
2005-10-25 09:22 |
ly4cn
const auto_ptr
对于const实体来说,只有类的构造函数、析构函数和声明后带有const的函数允许调用。
因此,对于const auto_ptr<>来说,它允许调用成员函数只有:get,operator*,operator->。
明显的,这几个函数不能转移所有权。
而用于转移所有权的release,reset等等函数均不能调用。如果调用了,将产生编译期错误。
回复
更多评论
#
re: const auto_ptr保证拥有权不能转移的实现原理?
2005-10-26 10:08 |
力为
多谢各位的提供的资料:)
回复
更多评论
刷新评论列表
标题
姓名
主页
验证码
*
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
boost::any 与 boost::variant 的区别
An Adapter Solution
fstream 和 中文路径
用std::find查找文件流中的内容
const auto_ptr保证拥有权不能转移的实现原理?
相关链接:
网站导航:
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子博客
管理