Search code examples
c++visual-studioc++17spdlog

Base Class causes Compilation Error (Visual Studio)


Beginner here.

I´ve recently written a bit of code to log using spdlog.

I based it on a "Singleton" base class and it doesn´t seem to be working, which irritates me, since in all other cases that I´m using that exact "Singleton" base class it works.

I get the following errors:

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

Some Resource to work off of

Singleton Class

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

Logging Class

#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;

    };

}
}

and (if necessary) the function it is being called from

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.

Thank you guys very much in advance for answering :D
Sorry if this is a stupidly simple question, I am a beginner and I couldn´t find the answer, eventhough it was probably staring me right in the face :)


Solution

  • [Answer given by "Igor Tandetnik" & "drescherjm"]

    Circular Includes!

    Singleton.h included Log.h, which led to a circular include, causing the compiler to go haywire.

    Always check what you include, this can also happen if you include another file that includes the file your including it in.
    It happened to me with my pch class.
    That´s why you shouldn´t include pch in headers i guess.