我爱Aspx >> VC.Net >> Don Box:Smart Pointers : What , Why , Which?Don Box:Smart Pointers : What , Why , Which?
H2>Smart pointers are objects that look and feel like pointers, but are smarter. What does this mean?
To look and feel like pointers, smart pointers need to have the same interface that pointers do: they need to support pointer operations like dereferencing (operator *) and indirection (operator ->). An object that looks and feels like something else is called a proxy object, or just proxy. and its many uses are described in the books and .
To be smarter than regular pointers, smart pointers need to do things that regular pointers don´t. What could these things be? Probably the most common bugs in C++ (and C) are related to pointers and memory management: dangling pointers, memory leaks, allocation failures and other joys. Having a smart pointer take care of these things can save a lot of aspirin...
The simplest example of a smart pointer is auto_ptr, which is included in the standard C++ library. You can find it in the header <memory>, or take a look at . Here is part of auto_ptr´s implementation, to illustrate what it does:
template <class T> class auto_ptr 【我对这篇文章有话说?】
企业上网的几个理由[05-21]
如何在Linux下实现设备的配置[05-21]
非窗口类中使用定时器的方法(二..[05-21]
非窗口类中使用定时器的方法(一..[05-21]
非窗口类中使用定时器的方法[05-21]
深度探索win32可执行文件格式[05-21]
const用法的体会[05-21]
一个典型的例子解决常见的高级Wi..[05-21]
由零开始做 Dialog (SDK版) — 在..[05-21]
C++机理:虚拟机制的实现[兼谈对..[05-21]