I have some const variables that I would like the values of to be shared between multiple source files. I would also like the variable's scope to be limited to a namespace. I am unsure of the best/correct way to do this?
I could use a #define but want to have the type safety.
So far I have the following which works:
File0.h
#pragma once
namespace Namespace1
{
extern const int variable1;
extern const int variable2;
}
File0.cpp
const int Namespace1::variable1 = 10;
const int Namespace1::variable2 = 10;
Source1.cpp
#include "File0.h"
int result1 = Namespace1::variable1 + Namespace1::variable2;
Source2.cpp
#include "File0.h"
const int result2 = Namespace1::variable1 + Namespace1::variable2;
With extern how do I know when the value has been initialized?