C++ Tutorials | L57: Static And Dynamic Or Early And Late Binding in C++ | The Easy Concepts

Опубликовано: 06 Январь 2025
на канале: The Easy Concepts
11,422
153

#programming #cplusplusprogramming #cprogramming
C++ Tutorials | L57: Static And Dynamic Or Early And Late Binding in C++ | The Easy Concepts

In this tutorial, we have discussed the static (early) and dynamic (late) binding in C++ using an example of base and derived class. We discussed the differences between static and dynamic binding, which shows that static binding is faster than dynamic binding as everything that is needed for a function call resolution is ready during compile time in static binding but not resolved till the run time in dynamic binding and therefore you can also term them as compile-time and run-time binding.

A virtual function is a member function that is declared within a base class and is re-defined(Overriden) by a 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.

Virtual functions ensure that the correct function is called for an object, regardless of the type of reference (or pointer) used for function call.

*They are mainly used to achieve Runtime polymorphism
*Functions are declared with a virtual keyword in the base class.
*The resolution of the function call is done at Run-time.

We also discussed the various ways through which base or derived classes can access their member functions. These methods are accessing the member functions using base class objects, derived class objects, base class pointers, derived class pointers, and aiming base class pointer at derived class objects. In this discussion, you will learn the need for virtual functions when aiming the base class pointer at derived class invoked base class functionalities.

To understand this discussion you should be first aware of the inheritance and its various types, which are given below -

Various types of inheritance are -

1. In single inheritance, a class is allowed to inherit from only one class. i.e. one subclass is inherited by one base class only.

2. Multiple Inheritance is a feature of C++ where a class can inherit from more than one class. i.e one subclass is inherited from more than one base class.

3. Multiple Inheritance is a feature of C++ where a class can inherit from more than one class. i.e one subclass is inherited from more than one base class.

4. Hierarchical Inheritance is a type of inheritance, where more than one subclass is inherited from a single base class. i.e. more than one derived class is created from a single base class.

5. Hybrid (Virtual) Inheritance is implemented by combining more than one type of inheritance. For example: Combining Hierarchical inheritance and Multiple Inheritance.

Please watch the full video to learn the concepts in more detail.

Learn Computer Science Concepts in an Easy Way !!

Website - http://www.theeasyconcepts.com/
Facebook -   / theeasyconcepts  
Twitter -   / theeasyconcepts  
GitHub - https://github.com/deepakuniyaliit/OOP
LinkedIn -   / deepak-uniyal-592b7545  
Telegram - https://t.me/theeasyconcepts