Virtual Function In C++

Описание к видео Virtual Function In C++

JOIN ME
—————
YouTube 🎬    / @cppnuts  
Patreon 🚀   / cppnuts  

COMPLETE PLAYLIST
————————————
C++ Tutorial For Beginners:    • Introduction To C++  
STL (Standard Template Library):    • STL In C++  
ThreadIng In C++:    • Multithreading In C++  
Data Structures:    • Data Structure  
Algorithms:    • Binary Search  
Design Patterns:    • Factory Design Pattern in C++  
Smart Pointers:    • Smart Pointer In C++  
C++14:    • Digit Separator In C++  
C++17:    • std string_view in C++17 | Fastest St...  
C++ All Type Casts:    • static_cast In C++  


INTERVIEW PLAYLIST
————————————
C++ Interview Q&A:    • Structural Padding & Packing In C & C++  
C++ Interview Q&A For Experienced:    • How delete[] Knows How Much  To Deall...  
Linked List Interview Questions:    • Find Kth Node From Back In Singly Lin...  
BST Interview Questions:    • Search Element In Binary Search Tree ...  
Array Interview Questions:    • Reverse An Array  
String Interview Questions:    • Check String Is Palindrome Or Not  
Bit Manipulation Questions:    • Find Set Bit In Integer Number  
Binary Tree Interview Question:    • Invert Binary Tree  
Sorting Algorithms:    • Bubble Sort  
C++ MCQ:    • Видео  
C MCQ:    • What printf returns after printing? |...  
C Interview Questions:    • Designated Initialization In C  

QUICK SHORT VIDEOS
————————————-
C++ Short :    • C++ Short Videos  
C Short :    • Shorts C Programming MCQ  

In this video we will learn about what is virtual function and how to use it in C++.

NOTES:
1. WHY to use virtual function?
a. To achieve dynamic polymorphism. Which is the ability to call Derived class function using Base class pointer or reference.

2. HOW to use virtual function?
a. By declaring function as virtual in Base class and overriding that function in Derived class.
(Function signature should be same in Base and Dervied class)
b. Declaring a function as virtual in Base class is enough, Derived class function need not to be declared virtual.
c. Virtual functions should be accessed using pointer(*) or reference(&) of Base class type to achieve run time polymorphism.

ADITIONAL NOTES:
1. Virtual functions cannot be static and also cannot be a friend function of another class.
2. A class can have virtual destructor but can't have virtual constructor.
3. There are two types of virtual functions in C++.
a. Virtual Function
b. Pure Virtual Function

#cpp #virtualfunction #programming #interviewquestions #softwareengineering #computerscience

Комментарии

Информация по комментариям в разработке