-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
48 lines (42 loc) · 854 Bytes
/
test.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
44
45
46
47
48
#include <iostream>
using namespace std;
class A {
public:
A() {}
A(int i) { _n = i; }
int _n = 5;
int n() const { return _n; }
};
// utility
const A operator+=(const A& a, const A& b){
return A(a.n() + b.n());
}
int main() {
A a;
cout << a.n() << endl;
A a2;
cout << a2.n() << endl;
a._n = 15;
a2._n = 10;
a2 += a; // the expr
cout << a2.n() << endl; // a2 was not modified
/*
double* const d = new double(2);
*d = 4; // ok
double d2 = 10;
d = &d2; // error: assignment of read-only variable ‘d’
d;
*/
//delete d
double* k = new double(3.14);
{
double b = 3.14;
k = &b;
cout << k << endl;
cout << *k << endl;
cout << "the point" << endl;
}
// cout << k << endl;
// delete k; //error
return 0;
}