Skip to content

Commit 99c2d25

Browse files
committed
Add Enums in C++
1 parent be7701a commit 99c2d25

File tree

4 files changed

+55
-22
lines changed

4 files changed

+55
-22
lines changed

HelloWorld/HelloWorld.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</ProjectConfiguration>
2020
</ItemGroup>
2121
<ItemGroup>
22+
<ClCompile Include="Log.cpp" />
2223
<ClCompile Include="src\Main.cpp" />
2324
<ClCompile Include="src\Static.cpp" />
2425
</ItemGroup>

HelloWorld/HelloWorld.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
<ClCompile Include="src\Static.cpp">
2222
<Filter>Fichiers sources</Filter>
2323
</ClCompile>
24+
<ClCompile Include="Log.cpp">
25+
<Filter>Fichiers sources</Filter>
26+
</ClCompile>
2427
</ItemGroup>
2528
</Project>

HelloWorld/Log.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <iostream>
2+
3+
class Log
4+
{
5+
public:
6+
enum Level
7+
{
8+
LevelError = 0,
9+
LevelWarning,
10+
LevelInfo
11+
};
12+
13+
private:
14+
Level m_LogLevel = LevelInfo;
15+
16+
public:
17+
void SetLevel(Level level)
18+
{
19+
m_LogLevel = level;
20+
}
21+
22+
void Error(const char* message)
23+
{
24+
if (m_LogLevel >= LevelError)
25+
std::cout << "[ERROR]:" << message << std::endl;
26+
}
27+
28+
void Warn(const char* message)
29+
{
30+
if (m_LogLevel >= LevelWarning)
31+
std::cout << "[WARNING]:" << message << std::endl;
32+
}
33+
34+
void Info(const char* message)
35+
{
36+
if (m_LogLevel >= LevelInfo)
37+
std::cout << "[INFO]:" << message << std::endl;
38+
}
39+
};
40+
41+
int main()
42+
{
43+
Log log;
44+
log.SetLevel(Log::LevelError);
45+
log.Warn("Hello!");
46+
log.Error("Hello!");
47+
log.Info("Hello!");
48+
std::cin.get();
49+
}

HelloWorld/src/Main.cpp

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

3-
struct Entity
3+
enum Example : char
44
{
5-
static int x, y;
6-
7-
static void Print()
8-
{
9-
std::cout << x << ", " << y << std::endl;
10-
}
5+
A, B, C
116
};
127

13-
int Entity::x;
14-
int Entity::y;
15-
16-
int main()
17-
{
18-
Entity::x = 2;
19-
Entity::y = 3;
20-
21-
Entity::x = 5;
22-
Entity::y = 8;
23-
24-
Entity::Print();
25-
Entity::Print();
26-
std::cin.get();
27-
}

0 commit comments

Comments
 (0)