Статическая библиотека предлагает статическую интеграцию через интерфейс ⇐ C++
Статическая библиотека предлагает статическую интеграцию через интерфейс
I am actually creating a static library (.lib) which will use a logger. I would like to offer the integrator the possibility of use his own logger.
To do that I tried to used static virtual pure function but I saw that this is impossible (there is a lot of topic about it)
Here is what I would like,
From static lib
enum class LogLevel final { kLogLevelTrace, kLogLevelDebug, kLogLevelInfo, kLogLevelWarn, kLogLevelError, kLogLevelCritical, kLogLevelOff, }; class ILogger { public: virtual ~ILogger() = default; virtual void TestLogMessage(const LogLevel& log_level, const std::string& log_message) = 0; }; class Logger final { public: static Logger& GetLogger() { static Logger logger; return logger; } static void LogMessage(const AltLogLevel& log_level, const std::string& log_message) { ILogger::TestLogMessage(log_level, log_message); } }; From integration:
class CustomLogger final : public ILogger { public: void TestLogMessage(const LogLevel& log_level, const std::string& log_message) override { std::cout
Источник: https://stackoverflow.com/questions/781 ... -interface
I am actually creating a static library (.lib) which will use a logger. I would like to offer the integrator the possibility of use his own logger.
To do that I tried to used static virtual pure function but I saw that this is impossible (there is a lot of topic about it)
Here is what I would like,
From static lib
enum class LogLevel final { kLogLevelTrace, kLogLevelDebug, kLogLevelInfo, kLogLevelWarn, kLogLevelError, kLogLevelCritical, kLogLevelOff, }; class ILogger { public: virtual ~ILogger() = default; virtual void TestLogMessage(const LogLevel& log_level, const std::string& log_message) = 0; }; class Logger final { public: static Logger& GetLogger() { static Logger logger; return logger; } static void LogMessage(const AltLogLevel& log_level, const std::string& log_message) { ILogger::TestLogMessage(log_level, log_message); } }; From integration:
class CustomLogger final : public ILogger { public: void TestLogMessage(const LogLevel& log_level, const std::string& log_message) override { std::cout
Источник: https://stackoverflow.com/questions/781 ... -interface
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение