What is smart pointer?
Submitted by: AdministratorSmart pointers are objects which store pointers to dynamically allocated (heap) objects. They are like built-in C++ pointers. However, they automatically delete the object pointed to at the appropriate time. They are useful as they ensure proper destruction of dynamically allocated objects (Exceptions). They can also be used to keep track of dynamically allocated objects shared by multiple owners.
They appear as owning the object pointed to and are responsible for deletion of the object when it is no longer needed.
The smart pointer library provides five smart pointer class templates:
scoped_ptr : Simple sole ownership of single objects. Noncopyable.
scoped_array: Simple sole ownership of arrays. Noncopyable.
shared_ptr: Object ownership shared among multiple pointers
shared_array: Array ownership shared among multiple pointers.
weak_ptr: Non-owning observers of an object owned by shared_ptr.
intrusive_ptr: Shared ownership of objects with an embedded reference count.
These templates are designed to complement the std::auto_ptr template.
Submitted by: Administrator
They appear as owning the object pointed to and are responsible for deletion of the object when it is no longer needed.
The smart pointer library provides five smart pointer class templates:
scoped_ptr : Simple sole ownership of single objects. Noncopyable.
scoped_array: Simple sole ownership of arrays. Noncopyable.
shared_ptr: Object ownership shared among multiple pointers
shared_array: Array ownership shared among multiple pointers.
weak_ptr: Non-owning observers of an object owned by shared_ptr.
intrusive_ptr: Shared ownership of objects with an embedded reference count.
These templates are designed to complement the std::auto_ptr template.
Submitted by: Administrator
Read Online C++ Pointers & Functions Job Interview Questions And Answers
Top C++ Pointers & Functions Questions
☺ | Can you please explain the difference between Pointer to constant and pointer constant? |
☺ | How many minimum number of functions are need to be presented in c++? |
☺ | Explain function pointers? |
☺ | Explain pointer with examples? |
Top C Plus Plus Language Categories
☺ | C++ Pointers & Functions Interview Questions. |
☺ | C++ Operator Overloading Interview Questions. |
☺ | C++ Exception Handling Interview Questions. |
☺ | C++ Template Interview Questions. |
☺ | C++ Virtual Functions Interview Questions. |