Consider a large-scale application where multiple threads often access shared objects concurrently. Which smart pointer can be used to ensure that an object is deleted only when the last pointer to it is out of scope, considering thread safety? 

  • raw pointer 
  • shared_ptr 
  • unique_ptr 
  • weak_ptr
shared_ptr is thread-safe in terms of its reference counting mechanism, ensuring that the object is safely managed across multiple threads and deleted only when the last pointer to it goes out of scope.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *