Virtual Functions & Abstract Classes in C++ | C++ Programming Tutorials

Sdílet
Vložit
  • čas přidán 27. 08. 2024
  • Support Simple Snippets by Donations -
    Google Pay UPI ID - tanmaysakpal11@okicici
    PayPal - paypal.me/tanmaysakpal11
    --------------------------------------------------------------------------------------------- In this video tutorial we will study and understand the concept of Virtual Functions and Abstract Classes and we will also see 2 practical examples of Virtual Functions.
    Virtual Function in C++ - A virtual function is a member function which is declared within base class and is re-defined (Overridden) by derived class.
    When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class’s version of the function.
    1) Virtual functions ensure that the correct function is called for an 2) object, regardless of the type of reference (or pointer) used for function call.
    3) They are mainly used to achieve Runtime polymorphism
    4) Functions are declared with a virtual keyword in base class.
    5) The resolving of function call is done at Run-time.
    Pure Virtual Functions & Abstract Class in C++ - Sometimes implementation of all function cannot be provided in a base class because we don’t know the implementation. Such a class is called abstract class.
    A pure virtual function (or abstract function) in C++ is a virtual function for which we don’t have implementation, we only declare it. A pure virtual function is declared by assigning 0 in declaration.
    Some important facts -
    1) A class is abstract if it has at least one pure virtual function.
    2) We can have pointers and references of abstract class type.
    3) If we do not override the pure virtual function in derived class, then derived class also becomes abstract class.
    4) Abstract classes cannot be instantiated.
    Download Dev C++ IDE : sourceforge.ne....
    Download C++ Android App : play.google.co...
    Simple Snippets Official Website -
    simplesnippets...
    Simple Snippets on Facebook-
    / simplesnippets
    Simple Snippets on Instagram-
    / simplesnipp. .
    Simple Snippets Google Plus Page-
    plus.google.co...
    Simple Snippets email ID-
    simplesnippetsinfo@gmail.com
    For Classroom Coaching in Mumbai for Programming & other IT/CS Subjects Checkout UpSkill Infotech - upskill.tech/
    UpSkill is an Ed-Tech Company / Coaching Centre for Information Technology / Computer Science oriented courses and offer coacing for various Degree courses like BSc.IT, BSc.CS, BCA, MSc.IT, MSc.CS, MCA etc.
    Contact via email /call / FB /Whatsapp for more info
    email - upskillinfotech@gmail.com
    We also Provide Certification courses like -
    Android Development
    Web Development
    Java Developer Course
    .NET Developer Course
    Check us out on Social media platforms like Facebook, Instagram, Google etc
    Facebook page - / upskillinfotech
    Insta page - / upskill_infotech
    Google Maps - goo.gl/maps/vj...

Komentáře • 194

  • @SimpleSnippets
    @SimpleSnippets  Před 5 lety +35

    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 ✌

  • @ritikpatil4077
    @ritikpatil4077 Před 3 lety +108

    Fun Fact :- You don't dare to increase playback speed.

  • @rockstarundercover
    @rockstarundercover Před 6 lety +41

    You videos saved my life! I have a test for which I fell asleep and didn’t prepare at all. Thank you! You are doing great :))

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety +4

      Thank you so much for such a wonderful response. Please do help me too. Share this video and channel with your friends and contacts and even they might go help from this ✌️😇

  • @zauneebyama2494
    @zauneebyama2494 Před 3 lety +16

    Man you are so good at teaching 😊
    The way you drop links of your related lectures is so helpful.
    Thanks a lot for saving my semester ❤️

  • @anuchechi9917
    @anuchechi9917 Před 4 lety +6

    The way you have explained all the videos on C++ concepts is just awesome. Thank you so much.

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety +1

      Most welcome ya 😊 this was a really motivating comment ✌️ please do share the video with your friends ✌️ that's the biggest help & support 😁

  • @vaidehimahyavanshi558
    @vaidehimahyavanshi558 Před 3 lety +4

    I don't understand how can someone dislike his videos I mean he is so good at explaining and he's better than any of the college teachers! Anyways thankyouuuu so much....

  • @aldoalayz
    @aldoalayz Před 3 lety +8

    Perfect explanation no bs straight to the point and also shows how it is useful, thanks!

  • @bharanikumarpatibandla1226

    best video lectures ever seen by mean.
    It is the only channel from which i can understand c++ !!
    Thank you very much.good work bro!!

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety

      Most welcome buddy. Glad to hear this from you. please do share this videos and our channel with your friends too bro, thats the biggest help and support 😇

  • @AdityaSingh-jh5qg
    @AdityaSingh-jh5qg Před 2 lety +2

    Tomorrow is my exam and Today I am here for Virtual function.
    And my this concept is clear.
    Thanks @SimpleSnippets

  • @kulaningobeni20
    @kulaningobeni20 Před 4 lety +10

    Great work, You have simplified what others complicate most of the time.

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety +1

      I'm glad I could make it easy. That's the biggest purpose of my channel 😊✌️

  • @gauravkumarverma5322
    @gauravkumarverma5322 Před 3 lety +2

    Bhai maza aa gaya! Kya samjhaya hai. Mere University ke teacher se to 100times bawal!!!

    • @SimpleSnippets
      @SimpleSnippets  Před 3 lety +1

      Hahahaha thank you Gaurav bhaai. Bohot acha laga ye comment padhke. please share kar do ye channel aapke dosto ke sath. Bohot help hojayegi!

  • @pawarb07
    @pawarb07 Před 5 lety +4

    Superb explanation !! it cleared my concept in just 15 mins.. excellent video man ..keep it up bro !!! you will go too far ..all the best

    • @SimpleSnippets
      @SimpleSnippets  Před 5 lety +2

      Thank you so much Bhushan 😊 super happy to hear this from you. I would request you to please share the video with your friends too ✌️😊 that'll be best 😊

  • @mohansivadhas
    @mohansivadhas Před 4 lety +1

    I am a intern in a product company and this video really helped me. Osm explenation!

  • @danishpatras4986
    @danishpatras4986 Před 3 lety +1

    2 example is very good example to understand the concept of abstract and virtual function

  • @bapudeewana7870
    @bapudeewana7870 Před 6 lety +8

    Last second Peace was very funny LOL

  • @AdityaSingh-ur9pr
    @AdityaSingh-ur9pr Před 4 lety +3

    Your OOP lecture series is a gem

  • @shivanibist256
    @shivanibist256 Před 3 lety +1

    Damn good 💯. You sound so confident from the start I was like yaa gotchaa. Gotchaa. Finally understood. There was no space for doubt. Thanks man.subscribed.✨

  • @soniyagupta3593
    @soniyagupta3593 Před 2 lety +2

    You are videos are life saving one day before exam ☺️ thx a lot dude

  • @isaacsakyi5997
    @isaacsakyi5997 Před 2 lety +1

    i am amazed at your teaching ability

  • @manansanson7959
    @manansanson7959 Před 3 lety +1

    you got quality in you videos, beautifully explained!! to the point!

  • @sathiadak5363
    @sathiadak5363 Před 4 lety +1

    I liked your way of method of teaching😊with good quality of sound...

  • @raunakkumar6144
    @raunakkumar6144 Před 10 měsíci +1

    Just love your explanation man !

  • @pgeditz666
    @pgeditz666 Před 2 lety

    God of c++ lecture 🙌

  • @maheshnahak9510
    @maheshnahak9510 Před 3 lety +1

    Excellent explanation Tanmay. Thanks a lot!!

  • @animeprogrammer
    @animeprogrammer Před 4 lety +1

    you don't have to create Animal class pointer because you can directly pass the Derived class object to the function with reference operator
    function1(&catObj);

  • @ridathemalik
    @ridathemalik Před 8 měsíci +1

    HEY IM IN 3RD SEMESETER RN AND I FOUND ALL THE LECTURES ON CZcams VERY LONG AND NOT WORHTY BUT YOUR LECTURES ARE TO THE POINT AND SHORT AND COVER EVERYTHING PLEASE TEACH DSA TOO.

  • @maheshbabu777
    @maheshbabu777 Před 4 lety +1

    Greatly Explained. Thanks for sharing knowledge.

  • @shankersalil8847
    @shankersalil8847 Před 3 lety +1

    very good explanation

  • @zakriabacha2477
    @zakriabacha2477 Před 6 lety +3

    sir , you teach in a so most excellent way

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety +1

      Thank you very much buddy. Happy to see your positive feedback. Please do share the videos with your friends too 😇

    • @zakriabacha2477
      @zakriabacha2477 Před 6 lety +1

      ok sir please make a video how to add graphics in dev c++ also thanks sir

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety

      Okay sure I'll try to cover that as well 😇✌️

    • @SahilKumar-ni7su
      @SahilKumar-ni7su Před 4 lety

      @@SimpleSnippets i year gone and you haven't

  • @samarthm4582
    @samarthm4582 Před 4 lety +5

    I guess i have come here late to appreciate you. Amazing work man.

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety +2

      Late is better than never Samarth. Thank you so much for such wonderful appreciation. Please do subscribe to our channel and definitely share it with your friends too 😇

  • @wajeehasiddiqi6878
    @wajeehasiddiqi6878 Před 2 lety +1

    please add a tutorial on virtual destructors as well as early as possible sir I have exams this weekend...I have watched all YOUR videos tis they helped me a lot get out of all the problems I had with this language. Tanmay sir it would be a great favor

  • @ManindraKhandyana
    @ManindraKhandyana Před rokem +1

    Sir, at 1:32, function overriding can not be achieved without virtual function!!!

  • @subhashr.p7643
    @subhashr.p7643 Před 3 lety +1

    Excellent Explanation. Use of Virtual function rel time example.. Awesome

  • @alfonsocastillosuarez5925

    Brilliant tutorial!

  • @ketangaikwad8617
    @ketangaikwad8617 Před 2 lety +1

    thank you so much sir!

  • @alessiomichelassi8390
    @alessiomichelassi8390 Před 4 lety +1

    Clever! thankyou very much. Great example!

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety

      Thank you so much buddy, Glad to hear this from you. Please do share the videos with your friends too bro 😇

  • @rashminirmale3040
    @rashminirmale3040 Před 4 lety +7

    The way of explaining is vary good ,neatly explained but need to be little slow the current video explanation is vary fast

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety +1

      Thanks Rashmi & yes I will remember maintaining a slower speed in future.

    • @MOROCCANFREEMIND
      @MOROCCANFREEMIND Před 3 lety

      Just slow down the speed of the video from options

  • @BringMe_Back
    @BringMe_Back Před 2 lety +1

    here to revise again :)

  • @HarshVerma-oz5uo
    @HarshVerma-oz5uo Před 3 lety +1

    If you have to create the Object of derived class anyway then why not call the derived class function directly instead of calling passing it to the Base class pointer. Hoping you will help me to understand that by not giving bookish defination

  • @Sabari-gd3fw
    @Sabari-gd3fw Před rokem

    Thanks for the explanation 👍

  • @sakshikakde5916
    @sakshikakde5916 Před 2 lety +1

    ur the best

  • @hoop5768
    @hoop5768 Před 4 lety +1

    plz tell at 13:55 why do we make one extra func...we can do it without it also naa???

  • @jamesnash9675
    @jamesnash9675 Před 2 lety

    you are the best.........masum

  • @harshalgarg1149
    @harshalgarg1149 Před 3 lety +1

    Thanks.

  • @babbubaliga2736
    @babbubaliga2736 Před 6 lety +6

    Excellent video man.

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety

      Thank you so much for the positive comment buddy. Do share the video with your friends and contacts 😇

  • @fleek4338
    @fleek4338 Před 3 lety +1

    Why to use Virtual function, when I can even run my code without using the virtual function??

  • @muhammadshafique9493
    @muhammadshafique9493 Před 3 lety +1

    much needed for that tutorials
    love from pakistan

  • @ysosrdude
    @ysosrdude Před 3 lety

    i have this problem where we need to call both virtual and derived function at the same time, and i can't understand how to do it

  • @vinaykumarhegde8557
    @vinaykumarhegde8557 Před 4 lety +3

    Thanks for sharing amazing content..!
    I have few queries hope I'll get response 👇:
    @1:31 Can you please tell that why specifically we need virtual function when override is possible using function overriding?

    • @ysosrdude
      @ysosrdude Před 3 lety +2

      because for function overloading, you either need different no. of parameters or different data type of parameters, so technically you will need to write use char for cat food and string for dog food, as an example and also you'll have to write the two functions seperately, which is not really feasible and it also wastes more memory bcuz it is two seperate functions. in virtual function he wrote only one function func1 and printed both dog and cat food with it, basically virtual functions can be used to sort of overload when your two functions are having same parameters or same data types

  • @cheezeypz1887
    @cheezeypz1887 Před 3 lety +3

    You're amazing, thank you so much!

    • @SimpleSnippets
      @SimpleSnippets  Před 3 lety

      You're very welcome! It would mean a lot if you could please share our channel and videos with your friends too ✌

  • @venkateshprasads8361
    @venkateshprasads8361 Před 3 lety +2

    great bro nice 👍

    • @SimpleSnippets
      @SimpleSnippets  Před 3 lety

      Glad you liked it! Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇

  • @yuyu-ce4fz
    @yuyu-ce4fz Před 4 lety +2

    really great, thanks.

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety

      Thanks buddy, glad to hear this. please do share the video with your friends too. Thats the biggest help and support 😇

  • @adityasarin39
    @adityasarin39 Před 4 lety +1

    Great video and explanations!

  • @techmatein
    @techmatein Před 4 lety +1

    Tanmay you rocks!

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety +1

      Thank you Kashif. Glad to hear this from you. Please share this video with your friends too 😇

    • @techmatein
      @techmatein Před 4 lety +1

      @@SimpleSnippets yep! Sure!

  • @its_time2learn
    @its_time2learn Před 3 lety +2

    Nice explination man

  • @henriquemedeiros2840
    @henriquemedeiros2840 Před rokem

    oh my god you have no idea of how much I love you lol

  • @rajatkhandelwal4803
    @rajatkhandelwal4803 Před 4 lety +1

    greattt brother!!!!

  • @shomiiii96
    @shomiiii96 Před 3 lety +1

    The accent and speech speed is a pain in the ass and my ears bleed, but damn it's a very high quality explanation with that second example of cats and dogs. Well done 👏

  • @mingukkie5008
    @mingukkie5008 Před 2 lety

    I have doubt as I'm a beginner so don't mind me you made Saperate void function
    but if we just directly points it like we did in first program something like this:
    Animal *ptr;
    Cat obj;
    Ptr=&pbj;
    Ptr->eat() ;
    So it's gonna work same right????

  • @vuhelpforum
    @vuhelpforum Před 4 lety +1

    Thanks alot

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety

      Most welcome. Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇

  • @jayaprasadb2044
    @jayaprasadb2044 Před 4 lety

    Without using the function1 we can print respective message for corresponding object

  • @st8738
    @st8738 Před 4 lety +1

    Great sir thanx a lot

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety

      Most welcome! Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇

  • @RaviShankar-oj7rg
    @RaviShankar-oj7rg Před 3 lety

    Thank You SO Much Sir

  • @adisingh9341
    @adisingh9341 Před 3 lety

    There is no card or link in top right corner coming

  • @yogeshdeshpande9532
    @yogeshdeshpande9532 Před 3 lety +1

    . thanks❤️

  • @zakriabacha2477
    @zakriabacha2477 Před 6 lety +1

    please make a video how to add graphics library in dev c++

  • @huyvole9724
    @huyvole9724 Před 6 lety +2

    Hi teacher, Can I understand "Virual Function same Override" ?

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety

      Hello, I didnt understand your question properly but yeah virtual functions also enable us to perform function overriding.

    • @huyvole9724
      @huyvole9724 Před 6 lety

      Thank you teacher ^^ my question: Virtual function is override ?

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety +1

      +Huy võ lê yes virtual functions help us in function overriding and dynamic polymorphism. ✌️

  • @AbhishekVerma-df2vq
    @AbhishekVerma-df2vq Před 6 lety +1

    Which programming language should I start right now. Please tell with consideration to Future. I am in class XII right now. After board exams, I want to learn programming.

  • @sureshbahadurshah2514
    @sureshbahadurshah2514 Před 3 lety

    How can an assingment operator (=) is used for objects without using operator overloading?

  • @supriyathakur2968
    @supriyathakur2968 Před 4 lety +1

    Very helpful video

    • @SimpleSnippets
      @SimpleSnippets  Před 4 lety

      Glad it was helpful! Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇

  • @shruthis7302
    @shruthis7302 Před 5 lety +2

    can u plz upload videos on all concepts of classes and objects @simplesnippets

    • @SimpleSnippets
      @SimpleSnippets  Před 5 lety

      Here is the full playlist of C++ Programming, you might find your topics here - czcams.com/video/AKNGgAXTark/video.html

  • @acm_tharu793
    @acm_tharu793 Před 3 lety

    If we write program for pure virtual function then it will also for abstract class or not? As we know pure virtual function is known as abstract class..

  • @yuvrajsinghbajwa8039
    @yuvrajsinghbajwa8039 Před 3 lety

    what are different type of virtual functions?

  • @monomail5964
    @monomail5964 Před 3 lety

    Hy sir, I can write the whole C++ program but when the time to access the values to call the implementation. I am gonna stuck. Please can you teach me about this?

  • @AHMEDRAZA-xv3gl
    @AHMEDRAZA-xv3gl Před 4 lety +1

    Simple Snippets I wanna ask a question that can we make a function virtual in derived class as well or only in base class we can do it?

    • @vasuyadav2931
      @vasuyadav2931 Před 2 lety

      If the derived class has a child class inheriting from it then I think you can use virtual functions in that derived class. But I'm no expert in inheritance so please take this with a grain of salt.

  • @animespeedart8847
    @animespeedart8847 Před 2 lety

    There's not any tutorial on Composition :(

  • @saikirandeekonda5953
    @saikirandeekonda5953 Před 3 lety

    Encapsulation ke bareme batayiye sir

  • @rishitmathur3202
    @rishitmathur3202 Před 2 lety

    BTech electronics and communication technology k sem 3 mein oop ka exam hai kal. I will pass it because of this video

  • @deepalipatil9899
    @deepalipatil9899 Před 4 lety +1

    Great video !! very well explained. Kudos

  • @OmegaJazz
    @OmegaJazz Před 6 lety

    What is the difference between Visual C++ and Dev C++?
    Like im using VC++ and its fun, i haven't tried Dev C++.

  • @mahesh-jg3zx
    @mahesh-jg3zx Před 5 lety

    Sir you cannot answer for my question in the last video. Why we are using scope resolution

  • @neerajmahapatra5239
    @neerajmahapatra5239 Před 5 lety +3

    I will make shape area example by own ....😎😎😎
    How you make it so simple and easy to understand yaar correct speed correct language.
    Hats off to you👌👌👌👌

    • @SimpleSnippets
      @SimpleSnippets  Před 5 lety +1

      Thanks Neeraj 😊 super happy to keep hearing your amazing comments ✌️😊

  • @omkaryametkar
    @omkaryametkar Před 3 měsíci +1

    🎉

  • @yellamrajuharishwarsagar5734

    Bro which software are u using for black board ?

    • @SimpleSnippets
      @SimpleSnippets  Před 5 lety

      It's called smoothdraw4. It's free and open source ✌️

  • @lakshaybajaj-lr7sm
    @lakshaybajaj-lr7sm Před rokem

    superb :)

  • @karthikkrishnan8556
    @karthikkrishnan8556 Před 3 lety

    But without using virtual keyword alone would print out the value of generic class for me so could you explain what's the use of that standalone function?

  • @shruthis7302
    @shruthis7302 Před 5 lety

    can u plz upload d overloading of binary operators using friend functions

  • @AmanSingh-fh2kd
    @AmanSingh-fh2kd Před 6 lety +1

    please bro put all the video tutorial in sequence,,otherwise great job!!

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety

      Hey Aman, all the tutorials are pretty much in proper sequence only in the C++ programming playlist. Checkout this playlist in the playlists section of the channel ✌️😊

  • @dihedral6374
    @dihedral6374 Před 4 lety

    6:12 Why you are not using acess specifiers in Myderived ?

  • @bredmond812
    @bredmond812 Před 4 lety +1

    Why did you make baseptr as a pointer?
    EDIT: i notice later that you say it allows you to make it point to any object of MyBase class. You then utilize this later when you make function1 so that it can call cat or dog. I guess that is why...

  • @subtlesurfer
    @subtlesurfer Před 2 lety

    🔥🔥

  • @ranjanagaikwad6291
    @ranjanagaikwad6291 Před 5 lety +4

    Sir thordsa slow smjhaeye 😐

  • @kuldeepmeena3685
    @kuldeepmeena3685 Před 5 lety

    hii bro , i am kuldeep ,
    IN THIS video tut. i don't understand program that you made ..

  • @nirajjain04
    @nirajjain04 Před 5 lety +1

    Explanation!👍🤝

  • @crazyriwasharena3154
    @crazyriwasharena3154 Před 6 lety +2

    gud bro

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety

      +Technical Riwash thank you buddy. And sure will try to make videos on Python but currently already have a lot of tutorial requests so will first try to finish those ✌️

  • @themimic4261
    @themimic4261 Před 4 lety

    bro can u explain advanced c++ as well?

  • @niranjanamurthy4168
    @niranjanamurthy4168 Před 6 lety +1

    good

    • @SimpleSnippets
      @SimpleSnippets  Před 6 lety

      Thank you :-) Please share this with your friends and contacts too ✌ That will be the biggest help and support for our channel 😇

  • @moeezahmad7748
    @moeezahmad7748 Před 3 lety

    u did not tell about pure virtual

  • @r.ktechnicalpresent3513

    sir you slide pani halnuna note ko lagi

  • @smrpkrl
    @smrpkrl Před rokem

    9:02