Inside General.h
#ifndef GENERAL
#define GENERAL
namespace counternamespace{
int upperbound;
int lowerbound;
}
#endif
Inside Analyzer.h
#ifndef ANALYZER
#define ANALYZER
#include"General.h"
class Analyzer
{
public :
int var ;
int func();
};
#endif
Inside Test.h
#ifndef TEST
#define TEST
#include"Analyzer.h" //Error
class Test2
{
public:
Test2(void);
public:
~Test2(void);
};
#endif
In the above code when I don't add Analyzer inside Test.h everything is working fine. But after adding its showing the following linker error.
1>Test2.obj : error LNK2005: "int counternamespace::lowerbound" (?lowerbound@counternamespace@@3HA) already defined in Analyzer.obj
2>Test2.obj : error LNK2005: "int counternamespace::upperbound" (?upperbound@counternamespace@@3HA) already defined in Analyzer.obj
I have added the #ifndef/#endif. Then where I am doing the mistakd? Can anyone please let me know?