#include<iostream>
using namespace std;
class Log
{
public:
enum LogLevel
{
LogLevelError = 0, LogLevelWarn, LogLevelInfo
};
private:
LogLevel m_LogLevel = LogLevelInfo;
public:
void SetLevel(LogLevel level)
{
m_LogLevel = level;
}
void Error(const char* message)
{
if (m_LogLevel >= LogLevelError)
std::cout << "[ERROR]:" << message << std::endl;
}
void Warn(const char* message)
{
if (m_LogLevel >= LogLevelWarn)
std::cout << "[WARNING]:" << message << std::endl;
}
void Info(const char* message)
{
if (m_LogLevel >= LogLevelInfo)
std::cout << "[INFO]:" << message << std::endl;
}
};
int main()
{
Log log;
log.SetLevel(Log::LogLevelError);
log.Warn("Hello!");
log.Error("Hello!");
log.Info("Hello!");
std::cin.get();
}
C++枚举类
最新推荐文章于 2024-08-17 23:59:05 发布