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 22
33#define LOG (x ) std::cout << x << std::endl
44
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
66{
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;
910
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+ };
1417
1518int main ()
1619{
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 );
2523
2624 std::cin.get ();
2725}
You can’t perform that action at this time.
0 commit comments