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Рік тому
How has this only got 3.9k views! This is a fantastic explanation, thank you :D
@PortfolioCoursesРік тому
You're very welcome Brandon, I'm glad you enjoyed it! :-)
@user-rb8vv9pc5e6 місяців тому
I've watched many of your videos and the thoroughness of your explanations is wonderful. Awesome work!
@PortfolioCourses6 місяців тому
I'm really happy that you're enjoying the content, thank you for the kind feedback! :-D
@mosslnnxРік тому
I really enjoyed watching your tutorials, concise and clear and good examples, Thanks a lot.
@PortfolioCoursesРік тому
You’re welcome Miss, I’m glad you’re enjoying the tutorials! :-)
@M3t4likРік тому
Clear and concise explanation of the relationship between abstract classes and virtual functions. thank you:)
@PortfolioCoursesРік тому
You’re welcome, I’m glad that you found the explanation clear and concise! :-)
@clammyclams8968Рік тому
Very Professional Explanation. Thank You So Much.
@PortfolioCoursesРік тому
You're welcome, and thank you for the kind words! :-)
@ermangurses1278Рік тому
Very clear explanation, thank you!
@PortfolioCoursesРік тому
You're welcome Erman! :-)
@laali_puppyМісяць тому
Great explanation, thanks!
@user-zy9ev1nz3y8 місяців тому
Nice video, very clear
@PortfolioCourses8 місяців тому
I'm glad you found it clear! :-D
@mihaibozian11 місяців тому
Thank you sir, I've been struggling why do we need to instantiate a pointer to an abstract class, and now I got it.
@PortfolioCourses11 місяців тому
You’re welcome Bozian, I’m really glad to hear the video helped you out! :-)
@abrahamalejandroguzmancard629910 місяців тому
You are amazing!
@PortfolioCourses10 місяців тому
I'm glad you enjoyed the video! :-)
@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Рік тому
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!
@cndyflss6 місяців тому
thank you sm dude🥳🥳🥳🥳
@PortfolioCourses6 місяців тому
You’re very welcome, thank you for watching! :-)
@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Рік тому
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Рік тому
@@PortfolioCourses great answer, thank you :)
@PortfolioCoursesРік тому
You're welcome! :-)
@gabrieldias6430Рік тому
awesome video
@PortfolioCoursesРік тому
Thank you Gabriel! 🙂
@joelparkerРік тому
great!
@PortfolioCoursesРік тому
I'm glad you enjoyed the video Joel! :-)
@Bl0xxy4 місяці тому
You used the new keyword. How do i safely do that without memory leaks?
@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Рік тому
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Рік тому
@@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Рік тому
@@animeIsle That makes sense, I'm glad you figured it out! 🙂
@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Рік тому
@@animeIsle I totally agree that figuring it out yourself feels great, that's the "addiction" of programming. 🙂 And thanks for the kind words!
@mohannadrababah757Рік тому
Thank you so much
@PortfolioCoursesРік тому
You’re welcome Mohannad! :-)
@Victor-fl8ex2 роки тому
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
@PortfolioCourses2 роки тому
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-fl8ex2 роки тому
@@PortfolioCourses damn. Didn’t think about that. Thanks master!!