[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppSmartPointer

(C++) Smart pointer

'A smart pointer is a C++ class that mimics a regular pointer in syntax and some semantics, but it does more.', cited from Andrei Alexandrescu.

Smart pointers are classes around a pointer, to prevent errors.

Boiled down to the essential resource management, a smart pointer (in this case a std::auto_ptr) looks like this (slightly modified from [1]):

//auto_ptr boiled down to resource management (note that it cannot do anything except that)
template <class T>
class auto_ptr 
{
  public:
  auto_ptr(T * anyPointer = 0) :  mPointer(anyPointer) {}
  ~auto_ptr() { delete mPointer; }
  private:
  T * mPointer;
};


Some examples of smart pointers are: boost:: denotes that this smart pointer is from the Boost C++ Library.

Reference



last edited (November 16, 2006) by bilderbikkel, Number of views: 2879, Current Rev: 4 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.