When do you use smart pointer? Here I change this questions to another
question, When do you use pointer?
An new object remain in existence, until you delete it. (you control
the life time of it, maybe you create it in fun1,then delete it in
fun4. so the obj is neither stack life nor global life. You may or
may not transfer ownership between functions.)
When you want to dynamic create a obj in runtime according runtime
condition or user input. (maybe don’t create it. ) Below code
demonstrate previous two conditions. ToothBrush need to be control
life time and created dynamically.
Large array or resources, if you allocate in stack, it will cause stack
overflow. In practicse, this item is deprecated, because anytime when you use [] or new [], you need consider to use arrayor vector ans string!