File tree 6 files changed +28
-22
lines changed
6 files changed +28
-22
lines changed Original file line number Diff line number Diff line change 1
1
* .out
2
2
settings.json
3
- week01 /~$Lecture01.pptx
4
- week02 /~$Lecture02.pptx
5
- week03 /~$Lecture03.pptx
3
+ .DS_Store
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
using namespace std ;
3
3
4
- void increase (const int * pn)
5
- {
6
- int * pi ;
7
- pi = const_cast <int *>(pn);
8
- (*pi )++; // undefined behavior
9
- }
10
-
11
-
12
4
int main ()
13
5
{
14
6
int value1 = 100 ;
15
7
const int value2 = 200 ;
16
8
cout << " value1 = " << value1 << endl;
17
9
cout << " value2 = " << value2 << endl;
18
-
10
+
19
11
int * pv1 = const_cast <int *>(&value1);
20
12
int * pv2 = const_cast <int *>(&value2);
21
13
@@ -25,12 +17,14 @@ int main()
25
17
cout << " value1 = " << value1 << endl;
26
18
cout << " value2 = " << value2 << endl;
27
19
28
- int v2 = const_cast <int &>(value2);
20
+ int & v2 = const_cast <int &>(value2);
29
21
v2++;
30
22
cout << " value2 = " << value2 << endl;
31
23
32
- // cout << "*pv2 = " << (*pv2) << endl;
33
- // cout << "v2 = " << v2 << endl;
24
+ cout << " *pv2 = " << (*pv2) << endl;
25
+ cout << " v2 = " << v2 << endl;
34
26
35
- return 0 ;
27
+ return 0 ;
36
28
}
29
+
30
+
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ class Mat
20
20
21
21
int main ()
22
22
{
23
- Mat image (DataType:: TYPE8U);
23
+ Mat image (TYPE8U);
24
24
25
- if (image.getType () == DataType:: TYPE8U)
25
+ if (image.getType () == TYPE8U)
26
26
std::cout << " This is an 8U matrix." << std::endl;
27
27
else
28
28
std::cout << " I am not an 8U matrix." << std::endl;
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ int main ()
5
+ {
6
+ int i = 18 ;
7
+ float * p1 = reinterpret_cast <float *>(i); // static_cast will fail
8
+ int * p2 = reinterpret_cast <int *>(p1);
9
+
10
+ printf (" p1=%p\n " , p1);
11
+ printf (" p2=%p\n " , p2);
12
+
13
+ return 0 ;
14
+ }
Original file line number Diff line number Diff line change @@ -29,9 +29,9 @@ int main()
29
29
cout << person.getInfo () << endl;
30
30
cout << ps->getInfo () << endl; // danger if getInfo is not virtual
31
31
32
- // ps = dynamic_cast<Student*>(&person);
33
- // printf("address = %p\n", ps);
34
- // pp = dynamic_cast<Person*>(&student);
35
- // printf("address = %p\n", pp);
32
+ ps = dynamic_cast <Student*>(&person);
33
+ printf (" address = %p\n " , ps);
34
+ pp = dynamic_cast <Person*>(&student);
35
+ printf (" address = %p\n " , pp);
36
36
return 0 ;
37
37
}
You can’t perform that action at this time.
0 commit comments