I have declared some constant variable in seperate header (i.e., constant.h).
I include the constant.h in my debug.cpp as to access the variable.
I include the constant.h, debug.h in my main.cpp as to access the variable.
When I compile, the error it shows **multiple definition** of **IF_DEBUG_ENABLED**
.
Kindly tell me what is actually I'm doing wrong. Also, please note that this is my first day on my very first c/c++ application. I've never even read it in school.
My code source is as follows: as
/-- constant.h --/
#ifndef CONSTANT_H
#define CONSTANT_H
const char* APP_NAME = "ymcmcb";
const bool IF_DEBUG_ENABLED = true;
#endif // CONSTANT_H
/-- debug.h --/
#ifndef DEBUG_H
#define DEBUG_H
#include <QString>
class Debug
{
public:
static void Log(QString Message);
};
#endif // DEBUG_H
/-- debug.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");
}
See Question&Answers more detail:os