C++ global string shows up in different values

Viewed 38

I encountered something very strange today.

I have util.hpp, and util.cpp to share some const strings with the whole project.

In util.hpp:

extern const string stringOne;

static string stringTwo = "Foo" + stringOne;

In Util.cpp:

const string stringOne = "One";

There are many places in the codebase which uses stringTwo, and sometimes, stringTwo shows up with the correct value: "FooOne", and sometimes, it shows up as "Foo".

This is so strange, and I think it is a C++ compilation bug.

0 Answers
Related