-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.classes.cpp
41 lines (31 loc) · 1.1 KB
/
11.classes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#define LOG(x) std::cout << x << std::endl
class Player // classes are types
{
public:
int x, y;
int speed;
void Move(int xa, int xy)
{
x += xa;
y += xy;
}
}; // we need semicolon at the end of the class
int main()
{
Player player; // we created variable player which is of type Player
// variables that are made from class types are called objects
// and a new object variable is called instance
// by default class makes everything in it private that only its functions can access those variables
// so if we want to access variables outsideof class we should make it public
player.x = 5;
player.Move(-5, 5);
std::cin.get();
}
// A class is private by default, however with struct everything is public and if we want sth in it private we should write private
// so class and struct are basically similar but you can have a style of using them
// for example you can use struct whenever you want to have a structure that has only variables or named plain old data like mathematical vector class
struct vec2
{
float x, y;
};