-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinheritance9.cpp
More file actions
52 lines (51 loc) · 950 Bytes
/
Copy pathinheritance9.cpp
File metadata and controls
52 lines (51 loc) · 950 Bytes
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
42
43
44
45
46
47
48
49
50
51
52
/*function overriding,virtual function
*function overriding is used to describe virtual functions' redefination by a derivied class
->virtual function cant be friend
->can't be used with a constructor
->can't be used with a destructor
->cant not be static members of the classes
function overriding the defination differs and prototype is same
*/
#include<iostream>
using namespace std;
class base
{
int i;
public:
virtual void vfunc()
{
cout<<"BC vfunction\n";
}
};
class derived_1:public base
{
public:
void vfunc()
{
cout<<"D1 vfunction\n";
}
};
class derived_2:public base
{
public:
void vfunc()
{
cout<<"D2 vfunction\n";
}
};
int main()
{
base *p,b;
derived_1 d1;
derived_2 d2;
//ptr tp base
p=&b;
p->vfunc();
//ptr to derived_1
p=&d1;
p->vfunc();
//ptr to derived_2
p=&d2;
p->vfunc();
return 0;
}