I came across the shared_ptr
trick for mimicking the behaviour of virtual destructors on a Youtube video (https://www.youtube.com/watch?v=ZiNGWHg5Z-o&list=PLE28375D4AC946CC3&index=6), and upon searching the internet came across this SO answer: shared_ptr magic :)
Normally, if B inherits from A and has its own destructor, we need a virtual destructor in the base class A to ensure that B's destructor is correctly called. However, using shared_ptr
you can circumvent the need for a virtual destructor.
Since there is runtime overhead of vtable lookups in polymorphic functions, I became curious to know if the shared_ptr
trick can avoid this overhead.
Aucun commentaire:
Enregistrer un commentaire