Well, I'm learning C++ and never really learned how to do stuff that is not OO. I'm trying to get a bit more experience coding in C style.
GobalInformation.h
#pragma once
#ifndef GLOBALINFORMATION_H
#define GLOBALINFORMATION_H
#include "MapInformation.h"
namespace gi {
MapInformation mapInf;
};
#endif
I would like to be able to access gi::mapInf from every header and cpp in my project. Right now I'm including globalinformation.h in every header, so I'm getting linker errors with multiple definitions.
How can I work around the problem?
#pragma once
and header guards (BTW, without unique identifiers => dangerous)?#ifndef GLOBALINFORMATION_H_8FF7B23E1B4D11E18852C5D64824019B
,#define GLOBALINFORMATION_H_8FF7B23E1B4D11E18852C5D64824019B
. If you don't need portability I would recommend to only use#pragma once
if your compiler supports it.