|
项目描述: |
This smart pointer package provides 2 main classes for use
1. CountedPtr - Is a reference counted smart pointer that can be used with any type - Allows direct assignment to base class smart pointer by a derived class - Supports static and dynamic casts where they are supported by the underlying types - Uses the copy constructor to clone the pointed to object - Calls the right delete when done with object
2. BackPtr - Is a class for backward references, when the pointer is not owned - Can be assigned a CountedPtr - Can check if the underlying object is still valid - Can get a CountedPtr from a BackPtr if the underlying object is valid, otherwise an exception will be thrown. This prevents the problem of dangling pointers
这个智能指针类提供了两个主要的类:
1. CountedPtr -是一个引用计数的智能指针,可以用于任何类型;可以将直接分配到基类的指针用于派生类;支持静态和动态类型转换;可以使用拷贝构造函数来复制指向的对象;当处理完对象后会调用正确的delete 方法。
2. BackPtr - 当没有指针时,是一个向后引用的类;可以分配一个 CountedPtr;可以检查潜在的对象是否有效;如果潜在的对象有效,可以从BackPtr 中得到一个CountedPtr ,否则将返回一个异常。这样可以防止指针错误。
来源: http://www.codeguru.com/cpp_mfc/SmartPointerLove.shtml |
类别: |
|
发布者:
cbd002
|
|
最新发布源码包 |
软件包 |
版本号 |
日期 |
本地下载 |
SmartPointerLove |
 1.0  |
2004-04-09 |
下载 |
|
|