• 您的位置我爱Aspx >> VC.Net >> Don Box:Smart Pointers : What , Why , Which?
  • Don Box:Smart Pointers : What , Why , Which?

  • 作者:aspxer  来源:internet  日期:2007-5-21 23:48:24  关键字:
  • 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我对这篇文章有话说?
  • 广告位招租,广告代号:content_468_15
  • 上一篇:让应用程序从IE中获取键入的网址
    下一篇:企业上网的几个理由
  • 相关文章