-1

What are the best practices for using smart. Are there situations in which i should prefer using raw pointer instead of smart pointers?

For example, if i know that class A creates class B and is the only owner of B - if there a reason to use smart pointers?

If you know of any good articles on that subject, please share.

Erik Sapir
  • 23,209
  • 28
  • 81
  • 141

1 Answers1

1

If the pointer owns the object at any time, then use a smart pointer.

If the pointer does not own the object (i.e. the object is owned by another smart pointer and guaranteed to outlive this pointer), use a raw pointer.

user541686
  • 205,094
  • 128
  • 528
  • 886