Virtual Destructors | C++ Tutorial

  Рет қаралды 2,835

Portfolio Courses

Portfolio Courses

2 жыл бұрын

How and why to use virtual destructors in C++, including why they are very important to prevent memory leak bugs. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 19
@wlcrutch
@wlcrutch Жыл бұрын
Dude, thank you! Super clear! 🙏🏻🙏🏻🙏🏻
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@variancewithin
@variancewithin Жыл бұрын
your videos are criminally underrated.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad you think so! :-)
@jaissonmonteiro9232
@jaissonmonteiro9232 5 ай бұрын
Sorry my English, I am Brazilian 😅 anyway thanks for c++ tutorial playlist, I am learning so much with it 🤝👏🚀
@PortfolioCourses
@PortfolioCourses 5 ай бұрын
Awesome! :-)
@mihirjog2707
@mihirjog2707 2 ай бұрын
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?
@snowandl4195
@snowandl4195 2 жыл бұрын
I think you're like Bob Ross but in programming
@PortfolioCourses
@PortfolioCourses 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 Жыл бұрын
Thanks,Sir.🙌🏾
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Emmanuel! :-)
@xturki5741
@xturki5741 Жыл бұрын
u are the best
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Aww thanks for the kind feedback! :-)
@akashislam9127
@akashislam9127 Жыл бұрын
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.
@Victor-fl8ex
@Victor-fl8ex 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 жыл бұрын
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: kzfaq.info/get/bejne/Y6yFm6pqnc7IfH0.html
@Victor-fl8ex
@Victor-fl8ex 2 жыл бұрын
@@PortfolioCourses Now it makes sense. Thanks sir!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome! :-)
sort() Standard Library Function | C++ Tutorial
8:54
Portfolio Courses
Рет қаралды 9 М.
Pure Virtual Destructors | C++ Tutorial
18:12
Portfolio Courses
Рет қаралды 3 М.
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 40 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 34 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
Function Templates | C++ Tutorial
10:54
Portfolio Courses
Рет қаралды 6 М.
Destructors in Programming: Practical Demonstration
20:10
CodeBeauty
Рет қаралды 31 М.
Dynamic Binding (Polymorphism) With The Virtual Keyword | C++ Tutorial
9:57
Multiple Inheritance Deep Dive | C++ Tutorial
14:53
Portfolio Courses
Рет қаралды 9 М.
Virtual Destructor In C++
10:17
CppNuts
Рет қаралды 15 М.
Overloading Function Templates | C++ Tutorial
9:54
Portfolio Courses
Рет қаралды 7 М.
CONCURRENCY IS NOT WHAT YOU THINK
16:59
Core Dumped
Рет қаралды 89 М.
Virtual Destructors in C++
7:55
The Cherno
Рет қаралды 103 М.
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 40 МЛН