forked from AlirezaPeymanirad/APLabGitPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
46 lines (40 loc) · 689 Bytes
/
1.cpp
File metadata and controls
46 lines (40 loc) · 689 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
#include <iostream>
using namespace std;
class container {
protected:
//add protected
int size;
public:
float* p;
container(int s) :size(s) {}
int& getsize() { return size; }
//delete const
};
class vector :public container {
int call_num;
public:
vector(int l) :len(l), container(1 * 100) {
//call constructor
//delete explicit
p = new float();
}
int len;
int& getlen() {
//delete const
call_num++;
return len;
}
~vector() = default;
};
int main() {
container c1(100);
vector& v1 = (vector&)c1;
//static cast
container& r1 = v1;
container c2 = 100;
c2.getsize() = 20;
cout << c2.getsize();
vector v2 = 100;
v2.getlen() = 40;
cout << v2.getlen();
}