Unfortunately, such a thing is not possible at work, because
the machines on which the compilers are installed are not
connected to a network with external access, email, or any
such thing. They are totally isolated, with good cause. The
best I can do is try to manually type in an example on another
system. A side effect of that is typos, which I will try to
minimize, but they will still appear once in awhile.
What's preventing you from compiling it on the machine where you
are connected to the Internet? You may have to retype it (or
use some other mechanism, such as a diskette), but at least, the
code you post will be code which displays the error.
It is compilable with the exception of including iostream and
qualifying cout with std::, but I understand your being picky.
I wouldn't want to have to fix every detail of someone elses
code either.
The problem is that your posted code works, at least if I
correct the "apparent" errors (missing includes, etc.). So
probably, you've copied something wrong. The only way to
advance is for you to post code which doesn't work, in the same
way it doesn't work in your problem. That means that you need a
compiler on the machine you're posting from (g++ is certainly an
option here), that you then test your code, and verify that what
you've "copied" displays the symptoms you describe. Otherwise,
you're just wasting everyone's time, including your own.
I did indeed try that and the initialization of the string
never even gets hit. It leads me to believe something was
screwy with the way static initialization takes place. I since
found out that "static initialization occurs in no guarenteed
order". Makes me wonder, was this snippet of code occurring
from the initialization of some other static elsewhere?
Something, of course, that one could not possibly guess from the
code you posted.
Indeed it was. It seems the problem is that all my
code gets run as a result of some static variable being
instantiated...something I've never seen nor understand.
The constructors of static objects are called during
initialization. Anything any of those constructors calls gets
called.
But I guess I'll have to replace all my static variables with
functions that return references to static variables of their
own.
That's one solution, when it's necessary. I find it a good
policy, however, to first try and eliminate unnecessary dynamic
initialization of statics, and use of other statics in
constructors of objects which might be defined static. Not to
the point of distorting the logic otherwise, of course. But if
your code is really an example of what you're doing, then
replacing the std::string const with a C style string might be
an appropriate solution. (I have a number of cases where I use
a C style array of
struct Elem
{
char const* key;
PODtype value ;
} ;
and std::find_if, rather than std::map< std::string, ... >,
precisely for this reason. Once you've wrapped it in a class,
the small bit of added complexity in the implementation is
isolated, and it makes use much simpler if you don't have to
worry about order of initialization.)