I am still having a hard time understanding why
void work_with_foo(shared_ptr<foo> _foo);
is not recommended compared to
void work_with_foo(foo* _foo)
I understand that work_with_foo(foo& _foo)
is better, but a pointer as a parameter! What if someone calls delete _foo
?
Can someone explain me why?
I always use shared_ptr
, so for example, in my code...
shared_ptr<foo> ptr_foo(new foo);
//calling work_with_foo which takes foo pointer
work_with_foo(ptr_foo); //will this even work?