• EP 3 - [C++] Polymorphism, Function overriding and Virtual function.

  • 2021/06/21
  • 再生時間: 8 分
  • ポッドキャスト

EP 3 - [C++] Polymorphism, Function overriding and Virtual function.

  • サマリー

  • 🚥 polymorphism is the occurrence of two or more different morphs or forms.🚥In this episode, I am talking about Polymorphism and more specifically Runtime polymorphism. This episode is arranged in such a way that it will help you to understand the concept clearly. There are a few common interview questions and I am explaining the answer in the best possible way.You can read the transcript below.This is very important and frequently asked interview questions. Don't forget to subscribe to the podcast to get a notification.You can listen on➡️ Amazon Music (https://music.amazon.com/podcasts/c5ed5ab6-e4e8-4932-a397-b687c85465da/PROGRAMMING-GYAN)➡️ Spotify (Programming Gyan)➡️ Apple Podcast (https://podcasts.apple.com/us/podcast/programming-gyan/id1568920481)➡️ Stitcher (https://www.stitcher.com/podcast/programminggyan)➡️ Google Podcast (https://podcasts.google.com/feed/aHR0cHM6Ly9mZWVkcy5yZWRjaXJjbGUuY29tL2JiOWQxMjEzLTFjODctNGRmZS1hNjZhLTIyM2MxNTc5NTE2OQ)You have lots of options. So there is no reason not to listen. You can follow #programminggyanLinkedIn: ProgrammingGyan (https://www.linkedin.com/company/programminggyan)Twitter: @GyanProgramming (https://twitter.com/GyanProgramming)Instagram: @programming_gyan (https://www.instagram.com/programming_gyan)Facebook: @ProgrammingGyan (https://www.facebook.com/ProgrammingGyan) To know more about me and to read blogs visit www.jhadheeraj.comFollow me at#LinkedIn: @jhadheeraj (https://www.linkedin.com/in/jhadheeraj)#Twitter: @dheerajjha_03 (https://twitter.com/dheerajjha_03)#Instagram: @jha.dheeraj03 (https://www.instagram.com/jha.dheeraj03/-------------------------------------------------------------------------------------------Transcript:Welcome to Programming Gyan [C++]- Tips and Tricks with Dheeraj JhaEP 3 - Polymorphism, Function overriding, and Virtual function.  C++ is an object-oriented programming language. It supports all the OOP concepts. Today I am going to talk about one of the OOP concepts. Polymorphism. In biology, polymorphism is the occurrence of two or more different morphs or forms. It is the same in C++. Polymorphism in programming means the same name with a different implementation. This allows us to do an operation in many ways based on the input. In C++, you have two types of polymorphism: Overloading and Overriding. In this episode, I will talk about Overriding. And will talk about Overloading in another episode. It is important to know the use case where you can use the tool. The problem why we need a tool. I will talk in a format so that you will get to know all the things in sequence. This episode will also help you to prepare for common interview questions.  What is function overriding?Inheritance allows us to create derived classes from the base class and inherit features of the base class. When we create a derived class object and call a function defined in the base class, the base class function gets called. If we redefine this function of the base class in the derived class, we can call the derived class function using the derived class object. So what actually happened here is called Function Overriding. Code ref: https://godbolt.org/z/f4Wfbqcxn Remember here, function overriding is only possible when there is inheritance. Why we need a virtual function?In what scenario we use the virtual function?Now when we are talking about function overriding, it is important to talk about Virtual functions. So before we go deep into internals, let's understand why we need this? In which scenarios we can use this feature of C++? Consider you are developing an automotive application which deals with different types of vehicles. So you created a base vehicle class and derived different derived classes like a car, bike, etc. For simplicity, I will use the car and bike-derived classes. All the vehicles have some common high-level features like start, stop, accelerate, etc. So you added these functions in the base class and overridden them in derived classes. And you started using your derived classes with their own implementation. Everything is going well so far. You were enjoying your code and someday, you got a new requirement that the user will decide which vehicle he is using and your application should work as per the user's vehicle. Oh… Now you don’t know which vehicle the user owns when you are writing your code. The type of vehicle will be decided at runtime when a user is using the application. To solve this you can check the type of vehicle user is providing at run time and call the appropriate function for the vehicle type. But this is not a good solution as your application may support more types of vehicles in the future. Here comes the virtual function for rescue. Code to refer: https://godbolt.org/z/ebc1Pn5eP How virtual function works? In the base class, you write a Virtual keyword before the function declaration to create a virtual function. When you create a virtual ...
    続きを読む 一部表示

あらすじ・解説

🚥 polymorphism is the occurrence of two or more different morphs or forms.🚥In this episode, I am talking about Polymorphism and more specifically Runtime polymorphism. This episode is arranged in such a way that it will help you to understand the concept clearly. There are a few common interview questions and I am explaining the answer in the best possible way.You can read the transcript below.This is very important and frequently asked interview questions. Don't forget to subscribe to the podcast to get a notification.You can listen on➡️ Amazon Music (https://music.amazon.com/podcasts/c5ed5ab6-e4e8-4932-a397-b687c85465da/PROGRAMMING-GYAN)➡️ Spotify (Programming Gyan)➡️ Apple Podcast (https://podcasts.apple.com/us/podcast/programming-gyan/id1568920481)➡️ Stitcher (https://www.stitcher.com/podcast/programminggyan)➡️ Google Podcast (https://podcasts.google.com/feed/aHR0cHM6Ly9mZWVkcy5yZWRjaXJjbGUuY29tL2JiOWQxMjEzLTFjODctNGRmZS1hNjZhLTIyM2MxNTc5NTE2OQ)You have lots of options. So there is no reason not to listen. You can follow #programminggyanLinkedIn: ProgrammingGyan (https://www.linkedin.com/company/programminggyan)Twitter: @GyanProgramming (https://twitter.com/GyanProgramming)Instagram: @programming_gyan (https://www.instagram.com/programming_gyan)Facebook: @ProgrammingGyan (https://www.facebook.com/ProgrammingGyan) To know more about me and to read blogs visit www.jhadheeraj.comFollow me at#LinkedIn: @jhadheeraj (https://www.linkedin.com/in/jhadheeraj)#Twitter: @dheerajjha_03 (https://twitter.com/dheerajjha_03)#Instagram: @jha.dheeraj03 (https://www.instagram.com/jha.dheeraj03/-------------------------------------------------------------------------------------------Transcript:Welcome to Programming Gyan [C++]- Tips and Tricks with Dheeraj JhaEP 3 - Polymorphism, Function overriding, and Virtual function.  C++ is an object-oriented programming language. It supports all the OOP concepts. Today I am going to talk about one of the OOP concepts. Polymorphism. In biology, polymorphism is the occurrence of two or more different morphs or forms. It is the same in C++. Polymorphism in programming means the same name with a different implementation. This allows us to do an operation in many ways based on the input. In C++, you have two types of polymorphism: Overloading and Overriding. In this episode, I will talk about Overriding. And will talk about Overloading in another episode. It is important to know the use case where you can use the tool. The problem why we need a tool. I will talk in a format so that you will get to know all the things in sequence. This episode will also help you to prepare for common interview questions.  What is function overriding?Inheritance allows us to create derived classes from the base class and inherit features of the base class. When we create a derived class object and call a function defined in the base class, the base class function gets called. If we redefine this function of the base class in the derived class, we can call the derived class function using the derived class object. So what actually happened here is called Function Overriding. Code ref: https://godbolt.org/z/f4Wfbqcxn Remember here, function overriding is only possible when there is inheritance. Why we need a virtual function?In what scenario we use the virtual function?Now when we are talking about function overriding, it is important to talk about Virtual functions. So before we go deep into internals, let's understand why we need this? In which scenarios we can use this feature of C++? Consider you are developing an automotive application which deals with different types of vehicles. So you created a base vehicle class and derived different derived classes like a car, bike, etc. For simplicity, I will use the car and bike-derived classes. All the vehicles have some common high-level features like start, stop, accelerate, etc. So you added these functions in the base class and overridden them in derived classes. And you started using your derived classes with their own implementation. Everything is going well so far. You were enjoying your code and someday, you got a new requirement that the user will decide which vehicle he is using and your application should work as per the user's vehicle. Oh… Now you don’t know which vehicle the user owns when you are writing your code. The type of vehicle will be decided at runtime when a user is using the application. To solve this you can check the type of vehicle user is providing at run time and call the appropriate function for the vehicle type. But this is not a good solution as your application may support more types of vehicles in the future. Here comes the virtual function for rescue. Code to refer: https://godbolt.org/z/ebc1Pn5eP How virtual function works? In the base class, you write a Virtual keyword before the function declaration to create a virtual function. When you create a virtual ...

EP 3 - [C++] Polymorphism, Function overriding and Virtual function.に寄せられたリスナーの声

カスタマーレビュー:以下のタブを選択することで、他のサイトのレビューをご覧になれます。