-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest4.cpp
43 lines (41 loc) · 824 Bytes
/
test4.cpp
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
/*================================================================
* Filename:test4.cpp
* Author: KCN_yu
* Createtime:Wed 16 Dec 2020 02:42:45 PM CST
================================================================*/
#include <iostream>
#include <stdlib.h>
using namespace std;
struct A{
virtual int f(int x, int y){
cout << "A::f(int,int)\n";
return x+y;
}
virtual void f(int x){
cout << "A::f(int)\n";
}
};
struct B : A{
void f(int x){
cout << "B::f(int)\n";
}
};
struct C : B{
virtual int f(int x, int y){
cout << "C::f(int,int)\n";
return x+y;
}
};
int main(int argc, char *argv[])
{
B b, *pb = &b;
C c;
A *pa = &b;
pa->f(1);
//pb->f(1,2);
A& ra = c;
ra.f(1,1);
B& rb = c;
//rb.f(0,0);
return 0;
}