Virtual Destructors | C++ Tutorial

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 21

  • @variancewithin
    @variancewithin Рік тому

    your videos are criminally underrated.

  • @Lee13Mac
    @Lee13Mac 5 місяців тому +2

    Should the delete call within each class destructor be changed to delete[ ], given that new[ ] was used to allocate memory for the integer arrays?

  • @shafayet0198
    @shafayet0198 Рік тому +1

    can we use delete [] array; to free the array instated of a loop?

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      Great question Akash! :-) Because we allocates space using new (instead of new []), we de-allocate the space using delete (instead of delete []). To do otherwise would result in undefined behavior in C++: stackoverflow.com/a/2425749.

  • @mihirjog2707
    @mihirjog2707 7 місяців тому

    So is it a good practice to have your base class destructors always virtual, even if you're not using polymorphism?
    So that if we're to use it in future, we'll be safe?

    • @Lee13Mac
      @Lee13Mac 5 місяців тому

      I was thinking the same thing - my guess is that a downside of such a practice is the efficiency lost to dynamic binding over static binding in cases where dynamic binding is not strictly necessary.

  • @jaissonmonteiro9232
    @jaissonmonteiro9232 10 місяців тому +1

    Sorry my English, I am Brazilian 😅 anyway thanks for c++ tutorial playlist, I am learning so much with it 🤝👏🚀

  • @wlcrutch
    @wlcrutch 2 роки тому

    Dude, thank you! Super clear! 🙏🏻🙏🏻🙏🏻

  • @snowandl4195
    @snowandl4195 2 роки тому +7

    I think you're like Bob Ross but in programming

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +2

      Hahahahaha that makes me really happy that you would say that! :-D I actually love having a Bob Ross video on in the background when I'm programming.

  • @Emmanuel_Morris
    @Emmanuel_Morris 2 роки тому

    Thanks,Sir.🙌🏾

  • @Vichained
    @Vichained 2 роки тому

    To be honest, I have watched this video many times but there is something that still doesnt make sense to me: Why would you create a derivedclass objetct using a Base class pointer? what would it be useful for?

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +1

      Polymorphism is the reason, it can allow us to have an array of pointers to different types of child objects, with a loop working through the objects and calling each object's member functions. The binding of those function calls can be dynamic, which means each object can have its own 'behaviour' according to its type. Writing code like this can allow us to remove code duplication, and though it may not seem like it, it can actually be more understandable code in the long run too! This video talks about polymorphism more: ua-cam.com/video/-FUhG98hdLI/v-deo.html

    • @Vichained
      @Vichained 2 роки тому

      @@PortfolioCourses Now it makes sense. Thanks sir!

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      You’re welcome! :-)

  • @xturki5741
    @xturki5741 2 роки тому

    u are the best