Abstract Classes And Pure Virtual Functions | C++ Tutorial

  Переглядів 13,670

Portfolio Courses

Portfolio Courses

День тому

How and why to use abstract classes and pure virtual functions in C++. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

КОМЕНТАРІ: 44
@brandongill368
@brandongill368 Рік тому
How has this only got 3.9k views! This is a fantastic explanation, thank you :D
@PortfolioCourses
@PortfolioCourses Рік тому
You're very welcome Brandon, I'm glad you enjoyed it! :-)
@user-rb8vv9pc5e
@user-rb8vv9pc5e 6 місяців тому
I've watched many of your videos and the thoroughness of your explanations is wonderful. Awesome work!
@PortfolioCourses
@PortfolioCourses 6 місяців тому
I'm really happy that you're enjoying the content, thank you for the kind feedback! :-D
@mosslnnx
@mosslnnx Рік тому
I really enjoyed watching your tutorials, concise and clear and good examples, Thanks a lot.
@PortfolioCourses
@PortfolioCourses Рік тому
You’re welcome Miss, I’m glad you’re enjoying the tutorials! :-)
@M3t4lik
@M3t4lik Рік тому
Clear and concise explanation of the relationship between abstract classes and virtual functions. thank you:)
@PortfolioCourses
@PortfolioCourses Рік тому
You’re welcome, I’m glad that you found the explanation clear and concise! :-)
@clammyclams8968
@clammyclams8968 Рік тому
Very Professional Explanation. Thank You So Much.
@PortfolioCourses
@PortfolioCourses Рік тому
You're welcome, and thank you for the kind words! :-)
@ermangurses1278
@ermangurses1278 Рік тому
Very clear explanation, thank you!
@PortfolioCourses
@PortfolioCourses Рік тому
You're welcome Erman! :-)
@laali_puppy
@laali_puppy Місяць тому
Great explanation, thanks!
@user-zy9ev1nz3y
@user-zy9ev1nz3y 8 місяців тому
Nice video, very clear
@PortfolioCourses
@PortfolioCourses 8 місяців тому
I'm glad you found it clear! :-D
@mihaibozian
@mihaibozian 11 місяців тому
Thank you sir, I've been struggling why do we need to instantiate a pointer to an abstract class, and now I got it.
@PortfolioCourses
@PortfolioCourses 11 місяців тому
You’re welcome Bozian, I’m really glad to hear the video helped you out! :-)
@abrahamalejandroguzmancard6299
@abrahamalejandroguzmancard6299 10 місяців тому
You are amazing!
@PortfolioCourses
@PortfolioCourses 10 місяців тому
I'm glad you enjoyed the video! :-)
@omercandemirci6410
@omercandemirci6410 Рік тому
Altough my english is bad. I understand purposes of abstract classes. In view of that situation I should say you are good teacher. Thanks
@PortfolioCourses
@PortfolioCourses Рік тому
I'm really glad to hear that you enjoyed the video Ömer, and thank you for the kind words! :-) And by the way your written english seems pretty good to me!
@cndyflss
@cndyflss 6 місяців тому
thank you sm dude🥳🥳🥳🥳
@PortfolioCourses
@PortfolioCourses 6 місяців тому
You’re very welcome, thank you for watching! :-)
@dzeno7370
@dzeno7370 Рік тому
What is the purpouse of using pointers to classes (a.k.a objects) in your example (and also couple of previous videos) if you are not using anything pointer-related stuff such as pointer arithmetics ? Could you do all those examples with something like Shape shapes [] = {Triangle(3,4), Rectangle(5,6)} ..... Can you also quickly elaborate what is the main adventage in general sense of dealing with object using pointers to instances, rather than object instances itself? One more thing: Does polymorphism work only with pointers so maybe you are using "Shape *shapes[]" on purpouse instead of "Shape shapes[]" ?
@PortfolioCourses
@PortfolioCourses Рік тому
These are great questions! :-) Objects that are instantiated using local variables of a function will exist in a portion of memory called 'the stack' that is managed for us automatically, they will have the lifetime of that function call (i.e. the memory that object uses on the stack will be freed when the function returns). But objects that are dynamically allocated (e.g. with 'new') exist on 'the heap', a separate portion of memory that we need to manually manage (e.g. by calling 'delete' to free the memory that object is using). We use pointers to refer to objects that have been dynamically allocated on the heap. Technically, we can use pointers to refer to objects on the stack as well. But using pointers allows to keep a "pointer" (i.e. memory address) to these objects on the heap, and that pointer can be passed around to different functions so they can access the same object too. Sometimes we'll have code where one function creates the object with dynamic memory allocation, and much later, a different function will free the memory associated object, using the pointer to the object. And I do not believe it is possible to implement runtime polymorphism without pointers, as the idea with runtime polymorphism is that the exact method to be called is determined at runtime when the member function of the object the pointer is pointing to is accessed. I don't know how that could really be possible without pointers, but sometimes in languages like C++ that are so large and have so many features, I'll find out there are ways of doing things that I'm totally unaware of. :-) This comment on stackoverflow also seems to suggest that it is not possible though: stackoverflow.com/a/7223724
@dzeno7370
@dzeno7370 Рік тому
@@PortfolioCourses great answer, thank you :)
@PortfolioCourses
@PortfolioCourses Рік тому
You're welcome! :-)
@gabrieldias6430
@gabrieldias6430 Рік тому
awesome video
@PortfolioCourses
@PortfolioCourses Рік тому
Thank you Gabriel! 🙂
@joelparker
@joelparker Рік тому
great!
@PortfolioCourses
@PortfolioCourses Рік тому
I'm glad you enjoyed the video Joel! :-)
@Bl0xxy
@Bl0xxy 4 місяці тому
You used the new keyword. How do i safely do that without memory leaks?
@animeIsle
@animeIsle Рік тому
Uhm why am I getting this error? I don't understand why I am getting this at all, btw this error is apparently in the for loop cout command: "no match for 'operator
@PortfolioCourses
@PortfolioCourses Рік тому
I'm not sure, it's hard to know without seeing your code. The original code for the video is found here: github.com/portfoliocourses/cplusplus-example-code/blob/main/abstract_class.cpp. Do you get the error if you use this code? Maybe there is a difference between this code and the code you're using? Apparently this error can happen if you use "end" instead of "endl" when outputting values, so maybe check for that, but the error can occur for other reasons as well.
@animeIsle
@animeIsle Рік тому
@@PortfolioCourses uhm I found the solution to it myself. Apparently if you use a method that uses cout command in a cout statement, then that error shows up. So I fixed it by simply calling the method outside of the cout statement. Thanks for replying though.
@PortfolioCourses
@PortfolioCourses Рік тому
@@animeIsle That makes sense, I'm glad you figured it out! 🙂
@animeIsle
@animeIsle Рік тому
@@PortfolioCourses Yea and oh boy, figuring it out yourself gives you a lot of satisfaction. You're surprisingly replying to the comments even if the video was uploaded quite a while ago. Hard to find people like you ngl. I respect you for that.
@PortfolioCourses
@PortfolioCourses Рік тому
@@animeIsle I totally agree that figuring it out yourself feels great, that's the "addiction" of programming. 🙂 And thanks for the kind words!
@mohannadrababah757
@mohannadrababah757 Рік тому
Thank you so much
@PortfolioCourses
@PortfolioCourses Рік тому
You’re welcome Mohannad! :-)
@Victor-fl8ex
@Victor-fl8ex 2 роки тому
Yo kevin, its me once again: its not a video-related question but, does template for switch case exist? for example i got this: case 1: std::cout
@PortfolioCourses
@PortfolioCourses 2 роки тому
The short answer is "not really". Rather than use templating, something like a function would be a better approach to reducing code duplication in this case.
@Victor-fl8ex
@Victor-fl8ex 2 роки тому
@@PortfolioCourses damn. Didn’t think about that. Thanks master!!
@PortfolioCourses
@PortfolioCourses 2 роки тому
@@Victor-fl8ex Haha you're welcome! :-D
Pure Virtual Destructors | C++ Tutorial
18:12
Portfolio Courses
Переглядів 2,6 тис.
The Flaws of Inheritance
10:01
CodeAesthetic
Переглядів 869 тис.
одни дома // EVA mash @TweetvilleCartoon
01:00
EVA mash
Переглядів 5 млн
Two Ways To Do Dynamic Dispatch
19:54
Logan Smith
Переглядів 68 тис.
Why You Should AVOID Linked Lists
14:12
ThePrimeTime
Переглядів 265 тис.
Every single feature of C# in 10 minutes
9:50
Train To Code
Переглядів 70 тис.
C++ Polymorphism and Virtual Member Functions [6]
12:13
Professor Hank Stalica
Переглядів 7 тис.
C++ Abstract base classes and pure virtual functions [7]
7:09
Professor Hank Stalica
Переглядів 2,5 тис.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Переглядів 1,9 млн
Object-oriented Programming in 7 minutes | Mosh
7:34
Programming with Mosh
Переглядів 3,7 млн
одни дома // EVA mash @TweetvilleCartoon
01:00
EVA mash
Переглядів 5 млн