Smart pointer

Such features are intended to reduce bugs caused by the misuse of pointers, while retaining efficiency.

Smart pointers typically keep track of the memory they point to, and may also be used to manage other resources, such as network connections and file handles.

Smart pointers were first popularized in the programming language C++ during the first half of the 1990s as rebuttal to criticisms of C++'s lack of automatic garbage collection.

Some work with reference counting, others by assigning ownership of an object to one pointer.

However, for reasons stated in the Section 2.2 process references are always indirect, through items called elements.

It is worth noticing the similarity between a process whose activity body is a dummy statement, and the record concept recently proposed by C. A. R. Hoare and N. WirthBecause C++ borrowed Simula's approach to memory allocation—the new keyword when allocating a process/record to obtain a fresh element to that process/record—it is not surprising that C++ eventually resurrected Simula's reference-counted smart-pointer mechanism within element as well.

In C++, a smart pointer is implemented as a template class that mimics, by means of operator overloading, the behaviors of a traditional (raw) pointer, (e.g. dereferencing, assignment) while providing additional memory management features.

Traditionally, naming conventions have been used to resolve the ambiguity,[6] which is an error-prone, labor-intensive approach.

C++11 introduced a way to ensure correct memory management in this case by declaring the function to return a unique_ptr, The declaration of the function return type as a unique_ptr makes explicit the fact that the caller takes ownership of the result, and the C++ runtime ensures that the memory will be reclaimed automatically.

It maintains reference counting ownership of its contained pointer in cooperation with all copies of the shared_ptr.

[citation needed] C++ Technical Report 1 (TR1) first introduced them to the standard, as general utilities, but C++11 adds more functions, in line with the Boost version.