I have a project that requires "creating a constant variable using an unnamed namespace", and I need to share it with functions in another .cpp file. It said the variable declarations could be in their own file. Use of the extern keyword was mentioned, and I figured out how to use extern, having the var in a header file and declared like extern const char varname;
, assigned it a value in my main.cpp, (const char varname = A;
globally above the main function) and was able to use it in the other .cpp file. But I'm not sure how to make use of an unnamed namespace. In an example file they have the following in the main file:
namespace
{
extern const double time = 2.0;
}
But there's now example of how to access that in another .cpp file. I tried doing that with my variable and I get an error in the other file where I try to use it saying it's not declared in that scope.
Can someone offer some insight as to what I should be doing here to make use of both of these things?