Skip to content

Commit be7701a

Browse files
committed
Add Static for Classes and Structs in C++
1 parent 2d2a357 commit be7701a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

HelloWorld/src/Main.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#include <iostream>
22

3-
extern int s_Variable;
3+
struct Entity
4+
{
5+
static int x, y;
6+
7+
static void Print()
8+
{
9+
std::cout << x << ", " << y << std::endl;
10+
}
11+
};
412

5-
void Function();
13+
int Entity::x;
14+
int Entity::y;
615

716
int main()
817
{
9-
std::cout << s_Variable << std::endl;
18+
Entity::x = 2;
19+
Entity::y = 3;
20+
21+
Entity::x = 5;
22+
Entity::y = 8;
23+
24+
Entity::Print();
25+
Entity::Print();
1026
std::cin.get();
1127
}

0 commit comments

Comments
 (0)