We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 031ac67 + bd2935a commit a227b6cCopy full SHA for a227b6c
C++/virtualFunction.cpp
@@ -0,0 +1,45 @@
1
+// Program to implement virtual function.
2
+
3
+#include <iostream>
4
5
+using namespace std;
6
7
+class Base {
8
+ public:
9
+ void display() {
10
+ cout<< "Display Base function.\n";
11
+ }
12
13
+ virtual void show() {
14
+ cout<< "Show Base function.\n\n";
15
16
+};
17
18
+class Derived: public Base {
19
20
21
22
23
24
+ void show() {
25
+ cout<< "Show Base function.\n";
26
27
28
29
+int main() {
30
+ Base B;
31
+ Derived D;
32
+ Base *bptr;
33
34
+ cout<<"bptr points to Base\n";
35
+ bptr = &B;
36
+ bptr->display();
37
+ bptr->show();
38
39
+ cout<<"bptr points to Derived\n";
40
+ bptr = &D;
41
42
43
44
+ return 0;
45
+}
0 commit comments