0

Smart Pointers challenge question

Smart pointers are a very important concept from C++ not covered in this course. I want you to explain with your own words what is a smart pointer and give examples of usage for unique_ptr and shared_ptr. Clearer explanation will be declared the winner.

17th Apr 2017, 10:38 AM
Denis Felipe
Denis Felipe - avatar
1 Réponse
+ 14
smart pointers are smart in memory allocations and deallocations in heap. we use new operator and allocate memory but sometimes we forget to deallocate it. if you declare a smart pointer it takes care of memory leaks and dangling pointers on its own. scoped_ptr cannot be copied whereas shared_ptr can be copied. if copied , it is smart enough to maintain use_count to calculate the number of pointers used. unique_ptr and weak_ptr has some specific use.
17th Apr 2017, 1:38 PM
manoj katari
manoj katari - avatar