I'm rewriting my code with smart pointer. I have such situation:
void Foo(SomeClass *p) { }
boost::shared_ptr<SomeClass> p(new SomeClass);
Now what to do: pass original pointer from wrapper (p.get()
) or rewrite function argument and pass smart pointer directly like:
void Foo(boost::shared_ptr<Foo> obj) { }
I'm not sure. As I understand smart pointers should follow some pointer and look whether it still need in program. So we can pass original pointer.
Unless Foo
needs to take (shared) ownership of *p
you should keep the signature the same and just pass p.get()
. It's the simplest and most flexible option as well as requiring the least change to your existing code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With