-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_const.cpp
More file actions
88 lines (81 loc) · 1.69 KB
/
Copy pathtest_const.cpp
File metadata and controls
88 lines (81 loc) · 1.69 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef int* INT1;
#define INT2 int*
class test_const {
int a;
int *p1 = new int[3];
int p2[2];
int& fun() const {
// a = 3;
p1[1] = 2;
// p2[1] = 3;
// return a;
// return p2[1];
return p1[1];
}
int print() {
fun() = 4;
cout << "test_const.p[1]: " << p1[1] << endl;
}
int x = print();
};
class test_const2 {
public:
int a;
void fun() const {
}
void fun2() {
}
};
int test1() {
test_const2 abc1;
const test_const2 abc = abc1;
abc.fun();
// abc.fun2();
}
int main() {
// vector<const int> vci;
vector<int> vi;
const int *p = new int();
delete p;
int a = 3;
// const int b;
const int c = a;
cout << "c: " << c << endl;
pair<const int, const int> pcci;
map<const int, const int> mcci;
// unordered_map<const int, int> umcci;
// unordered_map<const int, const int> umcci;
unordered_map<int, const int> umcci;
umcci.emplace(1,2);
umcci[2];
// umcci[1] = 2;
cout << "umcci size: " << umcci.size() << endl;
int const x = 3;
const int y = 4;
cout << "x + y: " << x + y << endl;
// x = y;
// y = x;
int *pi = new int(2);
int a11 = 0, a12 = 0, a21 = 0, a22 = 0;
const INT1 pint11 = &a11;
INT1 const pint12 = &a12;
const INT2 pint21 = &a21;
INT2 const pint22 = &a22;
// pint11 = pi;
// pint12 = pi;
pint21 = pi;
// pint22 = pi;
*pint11 = 3;
*pint12 = 3;
// *pint21 = 3;
*pint22 = 3;
int aa = 5;
const int& bb = aa;
// bb = 3;
test_const xx;
}