mercredi 28 août 2019

Casting of smart pointers

I have been using Raw pointers for a while , now i am trying to use Smart Pointers.

if ClassB is child of ClassA.

I can do this with raw pointers.

 ClassA* ptr = new ClassB;

Will this line be equivalent to the above line.

std::shared_ptr<ClassA> ptr = std::shared_ptr<ClassB>(new ClassB);

when ptr goes out of scope the memory will be cleared.

Aucun commentaire:

Enregistrer un commentaire