Possible Duplicate:
Which kind of pointer do I use when?
There are many pros in favour of C++11's smart pointers: They are safer, they're functionality and scope is more abvious etc.
Are the "classic" C like pointers
class C{};
C c;
C* c_p = &c;
obsolete now? Are they even deprecated? Or are there use cases where C pointers still make sense?
edit: The code snippet with a smart pointer:
class C{};
C c;
std::shared_ptr<C> c_p(new C());
edit: Thanks for pointing out the duplicate. From Xeo's answer there:
Use dumb pointers (raw pointers) or references for non-owning references to resources and when >you know that the resource will outlive the referencing object / scope. Prefer references and >use raw pointers when you need either nullability or resettability.
If that's all that there is, I accept that this question has been closed.
There are use cases where raw pointers make sense.
Raw pointers in modern code are 'non-owning' pointers. This means the code shouldn't do anything that requires or takes ownership of the pointed to object. For example it shouldn't be delete
d, used to construct an owning smart pointer, or saved beyond the current context.
Absolutely not. The smart pointers are for special cases, not for general use. Depending on the application and programming style, most pointers will still be raw pointers; in some cases, in fact, there may be no smart pointers at all.
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