I have a header file:
#ifndef DATA_HPP
#define DATA_HPP
#include <cstdint>
namespace f {
namespace t {
namespace e {
uint32_t a = 99;
class Test
{
public:
Test();
~Test();
};
}
}
}
#endif
With CPP file try.cpp:
#include "try.hpp"
namespace f {
namespace t {
namespace e {
Test::Test()
{
}
Test::~Test()
{
}
}
}
}
And the main file - main.cpp:
#include "try.hpp"
int main()
{
f::t::e::Test a;
}
But when I compile my code:
c++ --std=c++11 try.cpp main.cpp
I get below error:
(.data+0x0): multiple definition of `f::t::e::a'
try.cpp:(.data+0x0): first defined here
I already have the header file guard - so why the error is being reported and how can I fix it?