File tree Expand file tree Collapse file tree 6 files changed +28
-22
lines changed
Expand file tree Collapse file tree 6 files changed +28
-22
lines changed Original file line number Diff line number Diff line change 11* .out
22settings.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 11#include < iostream>
22using namespace std ;
33
4- void increase (const int * pn)
5- {
6- int * pi;
7- pi = const_cast <int *>(pn);
8- (*pi)++; // undefined behavior
9- }
10-
11-
124int main ()
135{
146 int value1 = 100 ;
157 const int value2 = 200 ;
168 cout << " value1 = " << value1 << endl;
179 cout << " value2 = " << value2 << endl;
18-
10+
1911 int * pv1 = const_cast <int *>(&value1);
2012 int * pv2 = const_cast <int *>(&value2);
2113
@@ -25,12 +17,14 @@ int main()
2517 cout << " value1 = " << value1 << endl;
2618 cout << " value2 = " << value2 << endl;
2719
28- int v2 = const_cast <int &>(value2);
20+ int & v2 = const_cast <int &>(value2);
2921 v2++;
3022 cout << " value2 = " << value2 << endl;
3123
32- // cout << "*pv2 = " << (*pv2) << endl;
33- // cout << "v2 = " << v2 << endl;
24+ cout << " *pv2 = " << (*pv2) << endl;
25+ cout << " v2 = " << v2 << endl;
3426
35- return 0 ;
27+ return 0 ;
3628}
29+
30+
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ class Mat
2020
2121int main ()
2222{
23- Mat image (DataType:: TYPE8U);
23+ Mat image (TYPE8U);
2424
25- if (image.getType () == DataType:: TYPE8U)
25+ if (image.getType () == TYPE8U)
2626 std::cout << " This is an 8U matrix." << std::endl;
2727 else
2828 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()
2929 cout << person.getInfo () << endl;
3030 cout << ps->getInfo () << endl; // danger if getInfo is not virtual
3131
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);
3636 return 0 ;
3737}
You can’t perform that action at this time.
0 commit comments