I encountered something strange this morning in my work and I really need to talk about it, I have a string object in an unnamed namespace in a header file, this last is included in the main cpp file and in other cpp files.
In main(), I have noticed when this global string object is using its =operator to set a value returned from a function (a non empty string), it stays empty ! whereas if I change the global string by a local string, this last is correctly updated with the new content. I remember encountering bizarre behavior from global variables and I really want to know what's going on. It's like the compiler didn't compile the program correctly...
Is there some people who encountered something similar with global variables and understood what happened ?
I fixed the problem by repalcing the unnamed namespace with a class and declaring the string static inside it.