SHOW:
|
|
- or go back to the newest paste.
1 | // Test.cpp : Defines the entry point for the console application. | |
2 | // | |
3 | ||
4 | #include "stdafx.h" | |
5 | #include <iostream> | |
6 | #include <stdlib.h> | |
7 | ||
8 | using namespace std; | |
9 | ||
10 | struct BOD | |
11 | { | |
12 | int x; | |
13 | int y; | |
14 | }; | |
15 | ||
16 | BOD *MyFunc1(BOD *val1) | |
17 | { | |
18 | return val1; | |
19 | }; | |
20 | ||
21 | BOD &MyFunc2(BOD &val1) | |
22 | { | |
23 | return val1; | |
24 | }; | |
25 | ||
26 | BOD MyFunc3(BOD &val1) | |
27 | { | |
28 | return val1; | |
29 | - | cout << bod1->x << endl; |
29 | + | |
30 | ||
31 | int _tmain(int argc, _TCHAR* argv[]) | |
32 | { | |
33 | // *** DYNAMICKÁ DEKLARACE *** // | |
34 | BOD *b1 = new BOD; | |
35 | - | cout << bod3.x << endl; |
35 | + | |
36 | ||
37 | BOD *bod1 = MyFunc1(b1); // Vypíše 5 | |
38 | cout << bod1->x << endl; | |
39 | ||
40 | BOD &bod2 = MyFunc2(*b1); // Vypíše 5 | |
41 | cout << bod2.x << endl; | |
42 | ||
43 | BOD bod3 = MyFunc3(*b1); // Vypíše 5 | |
44 | cout << bod3.x << endl; | |
45 | ||
46 | // *** STATICKÁ DEKLARACE *** // | |
47 | BOD b2; | |
48 | b2.x = 6; | |
49 | ||
50 | BOD *bod4 = MyFunc1(&b2); // Vypíše 6 | |
51 | cout << bod4->x << endl; | |
52 | ||
53 | BOD &bod5 = MyFunc2(b2); // Vypíše 6 | |
54 | cout << bod5.x << endl; | |
55 | ||
56 | BOD bod6 = MyFunc3(b2); // Vypíše 6 | |
57 | cout << bod6.x << endl; | |
58 | ||
59 | system("PAUSE"); | |
60 | return 0; | |
61 | } |