My understanding is that anonymous namespaces are an idiomatic c++ way of solving certain problems (i.e. what C# and Java solve with static classes).
In the following example, I am attempting to access a std::string
which is declared in an anonymous namespace, but I get a compile-time error that aString
"does not name a type"
I have tried changing the line in question to std::string aString = "some text";
, but this results in the compiler complaining that aString
is ambiguous.
Is it possible to forward declare a variable in an anonymous namespace like this?
#include <iostream>
#include <string
namespace{
std::string aString;
}
aString = "some text";
int main()
{
std::cout << "aString = " << aString << std::endl;
return 0;
}