Search code examples
c++header-filesspdlog

Pointer macros are not functioning


I am making a logging system for an engine I am building and have run into an issue. I set up a number of macros for my engine but unfortunately, they don't seem to work. here is my code: Log.cpp

#include "Log.h"
#include "spdlog/sinks/stdout_color_sinks.h"

namespace Divided
{
    std::shared_ptr<spdlog::logger> Log::s_CoreLogger;
    std::shared_ptr<spdlog::logger> Log::s_ClientLogger;

    void Log::Init()
    {
        spdlog::set_pattern("%^[%T] %n: %v%$");
        s_CoreLogger = spdlog::stdout_color_mt("DIVIDED");
        s_CoreLogger->set_level(spdlog::level::trace);
        s_ClientLogger = spdlog::stdout_color_mt("APP");
        s_ClientLogger->set_level(spdlog::level::trace);
    }
}

Log.h

#pragma once
#include <memory>
#include "Core.h"
#include "spdlog/spdlog.h"

namespace Divided
{
    class DIVIDED_API Log
    {
    public:
        static void Init();

        inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; }
        inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; }
    private:
        static std::shared_ptr<spdlog::logger> s_CoreLogger;
        static std::shared_ptr<spdlog::logger> s_ClientLogger;
    };
}

//core logging macros
#define DV_CORE_FATAL(...) ::Divided::Log::GetCoreLogger->fatal(__VA_ARGS__)
#define DV_CORE_ERROR(...) ::Divided::Log::GetCoreLogger->error(__VA_ARGS__)
#define DV_CORE_WARN(...)  ::Divided::Log::GetCoreLogger->warn(__VA_ARGS__)
#define DV_CORE_INFO(...)  ::Divided::Log::GetCoreLogger->info(__VA_ARGS__)
#define DV_CORE_TRACE(...) ::Divided::Log::GetCoreLogger->trace(__VA_ARGS__)
                           ::
//client logging macros    ::
#define DV_FATAL(...)      ::Divided::Log::GetClientLogger->fatal(__VA_ARGS__)
#define DV_ERROR(...)      ::Divided::Log::GetClientLogger->error(__VA_ARGS__)
#define DV_WARN(...)       ::Divided::Log::GetClientLogger->warn(__VA_ARGS__)
#define DV_INFO(...)       ::Divided::Log::GetClientLogger->info(__VA_ARGS__)
#define DV_TRACE(...)      ::Divided::Log::GetClientLogger->trace(__VA_ARGS__)

and core.h

#pragma once

#ifdef DV_PLATFORM_WINDOWS
    #ifdef DV_BUILD_DLL
        #define DIVIDED_API __declspec(dllexport)
    #else
        #define DIVIDED_API __declspec(dllimport)
    #endif
#else
    #error DIVIDED ONLY SUPPORTS WINDOWS!
#endif

when i call any of the macros visual studio says that left of -> must point to a data type. does any one know why this is braking


Solution

  • the solution here is really quite trivial. the way that the macros are defined now they will be a pointer to a function that is trying to call what should be a member function. this obviously will not work. what must be done is to add parentheses to the end of every call of GetClientLogger and GetCoreLogger so that the return type of these functions--classes--will call their correct and existing member functions.