File tree Expand file tree Collapse file tree 1 file changed +13
-15
lines changed Expand file tree Collapse file tree 1 file changed +13
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
#define LOG (x ) std::cout << x << std::endl
4
4
5
- void Increment ( int * value) // use pointer to get the memory address of the variable passed by as parameter so we can modify it.
5
+ class Player
6
6
{
7
- (*value)++; // dereference the value so that we can actually write to that memory instead of modifying the pointer itself
8
- }
7
+ public:
8
+ int x, y;
9
+ int speed;
9
10
10
- void Increment (int & value) // pass by references, exactly the same thing as above but clearer
11
- {
12
- value++;
13
- }
11
+ void Move (int xa, int ya)
12
+ {
13
+ x += xa * speed;
14
+ y += ya * speed;
15
+ }
16
+ };
14
17
15
18
int main ()
16
19
{
17
- int a = 5 ;
18
- int & ref = a; // ref is a, Reference is just creating an allias of a to be used as if it was a.
19
- ref = 2 ;
20
-
21
- LOG (a);
22
-
23
- Increment (a); // use ampersand to get the memory address reference of that variable
24
- LOG (a);
20
+ Player player;
21
+ player.x = 5 ;
22
+ player.Move (1 , -1 );
25
23
26
24
std::cin.get ();
27
25
}
You can’t perform that action at this time.
0 commit comments