我已经在单独的头文件中声明了一些常量变量(即constant.h)。
我在debug.cpp中包含了 constant.h 以访问该变量。
我在main.cpp中包含了constant.h和debug.h来访问变量。
当我编译时,它显示的错误**multiple definition** of **IF_DEBUG_ENABLED**
。
请告诉我实际上我做错了什么。另外,请注意这是我第一个 c/c++应用程序的第一天。我什至从未在学校读过它。
我的代码源如下:as
/ -- 常量.h -- /
#ifndef CONSTANT_H
#define CONSTANT_H
const char* APP_NAME = "ymcmcb";
const bool IF_DEBUG_ENABLED = true;
#endif // CONSTANT_H
/ -- 调试.h -- /
#ifndef DEBUG_H
#define DEBUG_H
#include <QString>
class Debug
{
public:
static void Log(QString Message);
};
#endif // DEBUG_H
/ -- 调试.cpp -- /
#include "constant.h"
#include "debug.h"
#include "QDebug"
static void Log(QString Message)
{
if (IF_DEBUG_ENABLED)
qDebug() << Message; //It says problem is here
}
/ -- main.cpp -- /
#include "constant.h"
#include "debug.h"
int main(int argc, char *argv[])
{
Debug::Log("New application has been run");
}