SMART POINTERS IN C++
Smart Pointers: a) A smart pointer is a wrapper over a raw pointer that automatically manages memory, ensuring proper deallocation and preventing memory leaks. b) Smart pointers are template-based, allowing use with any data type. c) They all are declared in <memory> header file. 1) auto_ptr 2) unique_ptr 3) shared_ptr 4) weak_ptr 1) auto_ptr: a) An object when described using the auto_ptr class, stores a pointer to a single allocated object which ensures that when it goes out of scope, the object it points to must get automatically destroyed. b) It is based on an exclusive ownership model i.e. two pointers of the same type can’t point to the same resource at the same time. Example: #include<iostream> using namespace std; class Class_S { public: void Show() { cout << "Class_S :: Show" << endl; } }; int main() { //raw pointer ...