how to declare and define global variables in order to access them from all headers/source files properly

In header file only do

namespace gi {
    extern MapInformation mapInf;
};

In CPP file provide the actual definition.

namespace gi {
    MapInformation mapInf;
};

It will work as you intend.

If you are using the MapInformation across dynamic link library boundaries you might have to link against the library that includes the definition cpp file. Also on Window you might have to use dllimport/dllexport

Leave a Comment