File tree 6 files changed +85
-29
lines changed
6 files changed +85
-29
lines changed Original file line number Diff line number Diff line change 1
- #include < cstdio>
1
+ // -----------------------------------------------------------------------------
2
+ //
3
+ // Source code for MIPT ILab
4
+ // Slides: https://sourceforge.net/projects/cpp-lects-rus/files/cpp-graduate/
5
+ // Licensed after GNU GPL v3
6
+ //
7
+ // -----------------------------------------------------------------------------
8
+ //
9
+ // Example for reference binding: displaying addresses
10
+ //
11
+ // ----------------------------------------------------------------------------
12
+
13
+ #include < iostream>
2
14
3
15
int foo () { return 42 ; }
4
16
5
17
int main () {
6
18
int x;
7
19
int &rx = x;
8
20
const int &l = foo ();
9
- printf (" %p\n " , &l);
10
- printf (" %p %p\n " , &x, &rx);
21
+ std::cout << &l << " " << &x << " " << &rx << std::endl;
11
22
}
Original file line number Diff line number Diff line change
1
+ // -----------------------------------------------------------------------------
2
+ //
3
+ // Source code for MIPT ILab
4
+ // Slides: https://sourceforge.net/projects/cpp-lects-rus/files/cpp-graduate/
5
+ // Licensed after GNU GPL v3
6
+ //
7
+ // -----------------------------------------------------------------------------
8
+ //
9
+ // Example: wrong pairing of new/delete and consequences
10
+ // compile with: g++ -g newdelete.cc
11
+ // try x/20x P-1 in gdb
12
+ //
13
+ // ----------------------------------------------------------------------------
14
+
15
+ #include < iostream>
16
+
17
+ struct MySmallClass {
18
+ int t = 1 ;
19
+ MySmallClass () { std::cout << " small ctor" << std::endl; }
20
+ ~MySmallClass () { std::cout << " small dtor" << std::endl; }
21
+ };
22
+
23
+ struct MyBigClass {
24
+ int t = 1 , p = 2 , q = 3 ;
25
+ MyBigClass () { std::cout << " big ctor" << std::endl; }
26
+ ~MyBigClass () { std::cout << " big dtor" << std::endl; }
27
+ };
28
+
29
+ int main () {
30
+ MyBigClass *S = new MyBigClass;
31
+ MySmallClass *T = new MySmallClass;
32
+ MyBigClass *P = new MyBigClass[5 ];
33
+ MySmallClass *Q = new MySmallClass[7 ];
34
+ delete[] T; // terribly wrong
35
+ }
Original file line number Diff line number Diff line change
1
+ // -----------------------------------------------------------------------------
2
+ //
3
+ // Source code for MIPT ILab
4
+ // Slides: https://sourceforge.net/projects/cpp-lects-rus/files/cpp-graduate/
5
+ // Licensed after GNU GPL v3
6
+ //
7
+ // -----------------------------------------------------------------------------
8
+ //
9
+ // Example: function signature for pointer and reference
10
+ // compile with: g++ -O1 -g0 -masm=intel -S ptref.cc
11
+ //
12
+ // ----------------------------------------------------------------------------
13
+
1
14
int g;
2
15
3
16
void foo (int *x) { g = *x; }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ // -----------------------------------------------------------------------------
2
+ //
3
+ // Source code for MIPT ILab
4
+ // Slides: https://sourceforge.net/projects/cpp-lects-rus/files/cpp-graduate/
5
+ // Licensed after GNU GPL v3
6
+ //
1
7
// ----------------------------------------------------------------------------
2
8
//
3
9
// Example for triangle intersection
4
- // Originated from homework of D. Bushev
10
+ // Originated from homework of Dmitry Bushev
5
11
//
6
12
// ----------------------------------------------------------------------------
7
13
Original file line number Diff line number Diff line change 1
- #include " lingeo.hpp"
1
+ // -----------------------------------------------------------------------------
2
+ //
3
+ // Source code for MIPT ILab
4
+ // Slides: https://sourceforge.net/projects/cpp-lects-rus/files/cpp-graduate/
5
+ // Licensed after GNU GPL v3
6
+ //
7
+ // -----------------------------------------------------------------------------
8
+ //
9
+ // Example: triangle intersection, driver program
10
+ //
11
+ // ----------------------------------------------------------------------------
12
+
13
+ #include < cassert>
2
14
#include < iostream>
3
15
#include < vector>
4
16
17
+ #include " lingeo.hpp"
18
+
5
19
polygon_t input_triangle () {
6
20
std::vector<point_t > verts (3 );
7
21
point_t temp;
8
22
for (int i = 0 ; i < 3 ; i++) {
9
23
std::cin >> temp.x ;
10
24
std::cin >> temp.y ;
11
25
verts[i] = temp;
26
+ assert (std::cin.good ());
12
27
}
13
28
polygon_t ret{verts};
14
29
return ret;
You can’t perform that action at this time.
0 commit comments