初学者在这里。
我最近写了一些代码来使用 spdlog 进行日志记录。
我将它基于“单例”基类,但它似乎没有工作,这让我很恼火,因为在所有其他情况下,我使用的正是它的“单例”基类。
我收到以下错误:
1>D:\dev\Makeshift\MakeshiftEngine\src\Utility\Log.h(20,33): error C2504: 'Singleton': base class undefined
1>D:\dev\Makeshift\MakeshiftEngine\src\Utility\Log.h(20,33): error C2143: syntax error: missing ',' before '<'
1>D:\dev\Makeshift\MakeshiftEngine\src\Utility\Log.h(24,16): error C3668: 'MS::Debug::Logger::Init': method with override specifier 'override' did not override any base class methods
一些可以利用的资源
单例类
namespace MS
{
template <class T>
class Singleton
{
public:
static T& Get();
virtual void Init() {};
virtual void Shutdown() {};
protected:
explicit Singleton<T>() = default;
};
template<typename T>
T& Singleton<T>::Get()
{
static_assert(std::is_default_constructible<T>::value, "<T> needs to be default constructible");
static T m_Instance;
return m_Instance;
}
} // namespace MS
日志记录类
#include "Utility/Singleton.h"
namespace MS
{
namespace Debug
{
class Logger : public Singleton<Logger>
{
public:
virtual void Init() override;
static std::shared_ptr<spdlog::logger> getConsole();
protected:
static std::shared_ptr<spdlog::logger> m_Console;
};
}
}
和(如有必要)调用它的函数
MS::Debug::Logger::Get().Init();
// For those who are downvoting, could you please explain why?
// Is it my formatting?
// or Is my question just THAT dumb?
// If it is the latter, I am sorry, but I would still greatly appreciate it if you could answer it.
非常感谢你们提前回答:D
对不起,如果这是一个愚蠢的简单问题,我是初学者,我找不到答案,尽管它可能正盯着我看:)