
There's more...
One possible workaround before C++17 was providing a static function, which returns a reference to a static object:
class foo {
public:
static std::string& standard_string() {
static std::string s {"some standard string"};
return s;
}
};
This way, it is completely legal to include the header file in multiple modules but still getting access to exactly the same instance everywhere. However, the object is not constructed immediately at the start of program but only on the first call of this getter function. For some use cases, this is indeed a problem. Imagine that we want the constructor of the static, globally available object to do something important at program start (just as our reciple example library class), but due to the getter being called near the end of the program, it is too late.
Another workaround is to make the non-template class foo a template class, so it can profit from the same rules as templates.
Both strategies can be avoided in C++17.