C++

Topic: Pointers

What are Kinds of Smart Pointers ?

The following section summarizes the different kinds of smart pointers that are available in the Windows programming environment and describes when to use them.C++ Standard Library Smart Pointers:Use these smart pointers as a first choice for encapsulating pointers to plain old C++ objects (POCO). unique_ptr        Allows exactly one owner of the underlying pointer. Use as the default choice for POCO unless you know for certain that you require a shared_ptr. Can be moved to a new owner, but not copied or shared. Replaces auto_ptr, which is deprecated. Compare to boost::scoped_ptr. unique_ptr is small and efficient; the size is one pointer and it supports rvalue references for fast insertion and retrieval from STL collections. Header file: <memory>. For more information, see How to: Create and Use unique_ptr Instances and unique_ptr Class.        shared_ptr        Reference-counted smart pointer. Use when you want to assign one raw pointer to multiple owners, for example, when you return a copy of a pointer from a container but want to keep the original. The raw pointer is not deleted until all shared_ptr owners have gone out of scope or have otherwise given up ownership. The size is two pointers; one for the object and one for the shared control block that contains the reference count. Header file: <memory>. For more information, see How to: Create and Use shared_ptr Instances and shared_ptr Class.        weak_ptr        Special-case smart pointer for use in conjunction with shared_ptr. A weak_ptr provides access to an object that is owned by one or more shared_ptr instances, but does not participate in reference counting. Use when you want to observe an object, but do not require it to remain alive. Required in some cases to break circular references between shared_ptr instances. Header file: <memory>. For more information, see How to: Create and Use weak_ptr Instances and weak_ptr Class.Smart Pointers for COM Objects (Classic Windows Programming): When you work with COM objects, wrap the interface pointers in an appropriate smart pointer type. The Active Template Library (ATL) defines several smart pointers for various purposes. You can also use the _com_ptr_t smart pointer type, which the compiler uses when it creates wrapper classes from .tlb files. It's the best choice when you do not want to include the ATL header files.    CComPtr Class Use this unless you cannot use ATL. Performs reference counting by using the AddRef and Release methods. For more information, see How to: Create and Use CComPtr and CComQIPtr Instances.    CComQIPtr Class        Resembles CComPtr but also provides simplified syntax for calling QueryInterface on COM objects. For more information, see How to: Create and Use CComPtr and CComQIPtr Instances.    CComHeapPtr Class        Smart pointer to objects that use CoTaskMemFree to free memory.    CComGITPtr Class        Smart pointer for interfaces that are obtained from the global interface table (GIT).    _com_ptr_t Class        Resembles CComQIPtr in functionality but does not depend on ATL headers.ATL Smart Pointers for POCO Objects : In addition to smart pointers for COM objects, ATL also defines smart pointers, and collections of smart pointers, for plain old C++ objects. In classic Windows programming, these types are useful alternatives to the STL collections, especially when code portability is not required or when you do not want to mix the programming models of STL and ATL.    CAutoPtr Class        Smart pointer that enforces unique ownership by transferring ownership on copy. Comparable to the deprecated std::auto_ptr Class.    CHeapPtr Class        Smart pointer for objects that are allocated by using the C malloc function.    CAutoVectorPtr Class        Smart pointer for arrays that are allocated by using new[].    CAutoPtrArray Class        Class that encapsulates an array of CAutoPtr elements.    CAutoPtrList Class        Class that encapsulates methods for manipulating a list of CAutoPtr nodes.

Browse random answers:

What is Pointers in c++ ?
What is importance of const. pointer in copy constructor?
Explain "passing by value", "passing by pointer" and "passing by reference"
Where we use reference and where we use pointers ?Write their differences and advantages and disadvantages .
Explain which of the following declarations will compile and what will be constant - a pointer or the value pointed at: * const char ** char const ** char * const
Why Pointers are not used in C Language. What are the main differences between C and C++
Explain about Reference operator (&) ?
Explain about declaring variables of pointer types with example ?
Explain about pointers and arrays ?
Explain about Pointer initialization ?
Explain about Pointer arithmetics ?
Explain about Pointers to pointers ?
Explain the void pointers with example ?
What is Null pointer ? 
What is Pointers to functions ?
What Are Pointers?
What are Using Pointers in C++ ?
Explain Accessing the Value at the Memory Address held by a Pointer ?
Why Use Pointers?
What are C++ Pointer Syntax ?
Explain about Taking Stock of Pointers ?
What are pointers? Why should you care?
Explain about Manipulating Data with Pointers and example ?
What are Array of pointers ?
Where do we use pointers?
Why do we need pointers?
Allocating a memory from the "Free Store" ?
Explain about Allocating a memory with new operator ?
Explain about De-allocating a memory with delete operator ?
Explain about Data type class pointers with example ?
Explain about memory leaks associated with pointers ?
Explain about memory leak caused by pointer reassignment ?
When local variable’s name is same as member’s name
What are function Pointer Syntax ?
What are Reading Function Pointer Declarations ?
What are Using a Function Pointer ?
What are Function Pointers in the Wild ?
How to Using Polymorphism and Virtual Functions Instead of Function Pointers (C++) ?
What are Benefits of Function Pointers ?
Where They get Useful  Function Arguments ?
Explain Smart Pointers (Modern C++) ?
What are Uses for smart pointers ?
What are Kinds of Smart Pointers ?
What are another Use of Pointers Efficient Array Processing ?
Explain about C++ Pointers and new
What are problems with pointers ?
Explain about generic smart pointer class ?
How to initialize a vector of pointers?
Explain about c++ Pointer Arithmetic ?
Explain about incrementing a Pointer ?
Explain  decrementing a Pointer ?
Explain pointer Comparisons ?