What are the things that we need to consider before replacing raw pointes with smart pointers in C++?

  • Thread starter Thread starter David student
  • Start date Start date
D

David student

Guest
Hello all,

I am using a legacy C++ project, In this project pointers are used in many places. we are thinking to implement best practices by replacing raw pointers with smart pointers.

I am having some knowledge about different types of smart pointers.

If the pointer is exclusively used by one object or a resource we choose unique_ptr

If the pointer is used by multiple objects or multiple resources then we choose shared_ptr

And if there is any cyclic dependency we use weak_ptr


What are the things that we need to consider before replacing with smart pointers?

Is there any risk involved in this process?

Do we need to consider the inherited classes as well here. Because, if these inherited class objects are also using the same pointers then can we choose sharted_ptr?

Continue reading...
 
Back
Top