What is the smart pointer in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the smart pointer in C++?

What is this?

20th Feb 2017, 7:31 AM
Vladyslav Yakymenko
4 Answers
+ 3
Thanks)
21st Feb 2017, 5:04 PM
Vladyslav Yakymenko
+ 2
So it is an object-wrapper? And releasing of memory happens because of narrowed scopes?
21st Feb 2017, 4:55 PM
Vladyslav Yakymenko
+ 1
the smart pointer like when there is no referance to it well be released from the heap examlpe: int *p = new int(5); // no. of ref to p is 1 int temp = *p; // no. of ref to p is 2 temp = 4; // no. of ref to p is 1 p = NULL; : // there is no referance to p // anymore... released safly (but of course it well be little bit more complicated)
21st Feb 2017, 4:49 PM
George Rabbat
George Rabbat - avatar
+ 1
yeah it also consider the method or the object scope it's just to privant memory leaks you may forget to release resources thats lead to memory leak
21st Feb 2017, 4:59 PM
George Rabbat
George Rabbat - avatar