Skip to content

Commit 2d2a357

Browse files
committed
Add Static in C++
1 parent 28a6dd2 commit 2d2a357

File tree

4 files changed

+13
-38
lines changed

4 files changed

+13
-38
lines changed

HelloWorld/HelloWorld.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</ItemGroup>
2121
<ItemGroup>
2222
<ClCompile Include="src\Main.cpp" />
23+
<ClCompile Include="src\Static.cpp" />
2324
</ItemGroup>
2425
<PropertyGroup Label="Globals">
2526
<VCProjectVersion>16.0</VCProjectVersion>

HelloWorld/HelloWorld.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
<ClCompile Include="src\Main.cpp">
1919
<Filter>Fichiers sources</Filter>
2020
</ClCompile>
21+
<ClCompile Include="src\Static.cpp">
22+
<Filter>Fichiers sources</Filter>
23+
</ClCompile>
2124
</ItemGroup>
2225
</Project>

HelloWorld/src/Main.cpp

+3-38
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
11
#include <iostream>
22

3-
class Log
4-
{
5-
public:
6-
const int LogLevelError = 0;
7-
const int LogLevelWarning = 1;
8-
const int LogLevelInfo = 2;
9-
10-
private:
11-
int m_LogLevel = LogLevelInfo;
12-
13-
public:
14-
void SetLevel(int level)
15-
{
16-
m_LogLevel = level;
17-
}
18-
19-
void Error(const char* message)
20-
{
21-
if (m_LogLevel >= LogLevelError)
22-
std::cout << "[ERROR]:" << message << std::endl;
23-
}
24-
25-
void Warn(const char* message)
26-
{
27-
if (m_LogLevel >= LogLevelWarning)
28-
std::cout << "[WARNING]:" << message << std::endl;
29-
}
3+
extern int s_Variable;
304

31-
void Info(const char* message)
32-
{
33-
if (m_LogLevel >= LogLevelInfo)
34-
std::cout << "[INFO]:" << message << std::endl;
35-
}
36-
};
5+
void Function();
376

387
int main()
398
{
40-
Log log;
41-
log.SetLevel(log.LogLevelError);
42-
log.Warn("Hello!");
43-
log.Error("Hello!");
44-
log.Info("Hello!");
9+
std::cout << s_Variable << std::endl;
4510
std::cin.get();
4611
}

HelloWorld/src/Static.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int s_Variable = 5;
2+
3+
static void Function()
4+
{
5+
6+
}

0 commit comments

Comments
 (0)