-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut50.cpp
More file actions
41 lines (32 loc) · 1.87 KB
/
tut50.cpp
File metadata and controls
41 lines (32 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
int main(){
/*
[******* Polymorphism in C++ *******]
“Poly” means several and “morphism” means form. So we can say that polymorphism is something that has several forms or we can say it as one name and multiple forms. There are two types of polymorphism:
Compile-time polymorphism
Run time polymorphism
Compile Time Polymorphism
In compile-time polymorphism, it is already known which function will run. Compile-time polymorphism is also called
early binding, which means that you are already bound to the function call and you know that this function is going
to run. There are two types of compile-time polymorphism:
Function Overloading
This is a feature that lets us create more than one function and the functions have the same names but their
parameters need to be different. If function overloading is done in the program and function calls are made the
compiler already knows that which functions to execute.
Operator Overloading
This is a feature that lets us define operators working for some specific tasks.
For example, we can overload the operator “+” and define its functionality to add two strings.
Operator loading is also an example of compile-time polymorphism because the compiler already knows at the compile
time which operator has to perform the task.
Run Time Polymorphism
In the run-time polymorphism, the compiler doesn’t know already what will happen at run time.
Run time polymorphism is also called late binding.
The run time polymorphism is considered slow because function calls are decided at run time.
Run time polymorphism can be achieved from the virtual function.
Virtual Function
A function that is in the parent class but redefined in the child class is called a virtual function.
“virtual” keyword is used to declare a virtual function.
*/
return 0;
}