繁体   English   中英

'DemoProject :: Logger':'class'类型重新定义

[英]'DemoProject::Logger' : 'class' type redefinition

我已经阅读了很多有关此问题的问题,但是似乎没有一个问题可以解决我的问题。 代码如下:

Logger.cpp

#include "Includes.h"

namespace DemoProject {
    class Logger {
    public:
        static void Logger::printm(CEGUI::String Message) {
            std::cout << currentDateTime() << " >> " << Message << std::endl;
        }

    private:
        static const std::string currentDateTime() {
            time_t     now = time(0);
            struct tm  tstruct;
            char       buf[80];
            tstruct = *localtime(&now);
            strftime(buf, sizeof(buf), "%d-%m-%Y %X", &tstruct);

            return buf;
        }
    };
}

logger.h

#ifndef LOGGER_H
#define LOGGER_H
#pragma once

#include "Includes.h"

namespace DemoProject {
    class Logger {
    public:
        static void Logger::printm(CEGUI::String Message);
    };
}

#endif

Includes.h

#ifndef INCLUDES_H
#define INCLUDES_H

#include <iostream>
#include <string>
#include <stdio.h>
#include <time.h>

#include <CEGUI/CEGUI.h>
#include <CEGUI/RendererModules/OpenGL/GLRenderer.h>

#include <SDL.h>
#include <SDL_opengl.h>

#include "Logger.h"

#endif

抱歉,帖子的格式不好,但这是我能做的最好的事情。 我主要是C#开发人员,但是我尝试通过自己做的不同练习来学习C ++。 从C#开发人员的角度来看,此代码还可以,但是我不知道,我仍然是初学者。

您做的几件事很奇怪。 但是最重​​要的是,您无需在.cpp文件中再次声明该类。 您只需实现以下功能:

namespace DemoProject {

    void Logger::printm(CEGUI::String Message) {
        std::cout << currentDateTime() << " >> " << Message << std::endl;
    }

    static const std::string currentDateTime() {
        ...
    }

}

您也没有在标头中声明currentDateTime,因此不会正确编译。 您也不需要在声明中限定类的范围,因为您已经在类中,因此标头应如下所示:

namespace DemoProject {
    class Logger {
    public:
        static void printm(CEGUI::String Message);
        static const std::string currentDateTime();
    };
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM