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.
4/17/2017 10:38:02 AMDenis Felipe
1 AnswerNew Answer
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.