Hey Guys, if you want more such tech educational videos on this channel then please support me by subscribing to this channel & also share it with your friends as it helps me create more content just for you ✌
Wow thank you so much for such an amazing review. Definitely the best positive response as well ❤️ Please do share the videos with your friends and contacts buddy. It'll be of great help 😇
Thank you very much Mohan, really happy to see such support from you. And yes thank you for sharing this video and channel and spreading the knowledge 🙏
I know how to use virtual function,pure virtual function but I can't understand where to use it because instead of using them we can directly use normal member function override then why we use them ?
Please clarify: From the basics we know that we cannot have a pointer or reference without an object bound to it. ( Strictly speaking we can have a nullptr, we are talking about class objects here) Now, we cannot have objects of abstract class type, and that is true by theory. So how can we have pointers and references of abstract class type? (2nd fact you mention at 1:40). Thanks
Thats really great to know buddy🙏 Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇
I did the exact code in my IDE, however, I removed the pure virtual function and it still works fine when creating and calling getArea() methods for the circle and rectangle class. May I know what is a pure virtual function used for?
In derived class you used public again this is the first you using public in derived class In previous videos you used public access specifier only in base classes not it derived classes When I didn't use public access specifier in derived class it showed me an error and it is private Can you explain why??
Let's say you create parent class as animal and create sound() method in it. Then you create 2 child classes of cat and dog and inside that you want individual sound methods for each class. In cat the sound () method should print - cats meow and for dogs class the sound () method should say - dogs bark Now if you come to the parent animal class unless you know what type of animal it is, you cannot have anything inside the sound () method right? Because it won't make sense since we do not know what animal it is. So hence we use pure virtual function when we don't know what exactly the parent class method/function is going to do.
@@SimpleSnippets ok got it Thanks for quick response Hope u rply me for my other doubt also which i have commented on other video as well asap Once again thankee buddy
That's exactly what I explained here buddy. Until an unless you don't know what animal it is, how can you create the sound method in the base class? Cause sound method of one animal with be different to that of the other 🤟
This is not a good example of a pure virtual function. In this scenario you don't need a class shape to make the main function work. You need to use pointers to show a good example of a pure virtual function.
You can do it by yourself using pointer like this int main() { shape *ptr; circle c1; ptr=&c1; ptr->getarea(); rectangle r1; ptr=&r1; ptr->getarea(); }
This tutorial is completly useless; you can delete the whole shape class and the programm would work exactly the same? So what is the point of using an example to explain a concept, where the concept isn't even used? For all the ones that are confused: - you cannot create an object of an abstract class BUT you can create a pointer of an abstract class - then considering his video of virtual functions (which was really good) you can acess all different getArea() functions with a single pointer type Hope that helps :)
This helped a lot! You can create a pointer of Shape type, then create Rectangle and Circle object and make the Shape pointer point to one of those objects, for example circleObj, and then by using ptr->getArea the area of the circle will be printed! Then if we need the area of the rectangle the Shape pointer can then point to the rectangle and by using ptr->getArea the area of the rectangle will be printed! Amazing!
Bro if we create pointer of base class and point to derived objects then also we are creating derived objects right when we can simply call the function through derived objects itself then why to create a base pointer and if we dont create pointer and do the same as shown in the video then also it is confusing me like why to use pure virtual function it is just simply overriding the function itself i didnt seen the use of pure virtual function in this example because if we remove the pure virtual function also then also it works fine.. plz help me guys🥺🥺😖😖