Original Post
Hello, everyone! There's a small misunderstanding with stl strings. The problem, it seems, plagued our whole project, and I have no idea what is wrong here. Let's say there's an object with string as one of its members, something like this: struct testObj { std::string text; }; now, in case we do something like this: testObj a, b; a.text = "12345678901234567890"; b = a; OMG, The assignment actually works! "b.text" has the value "12345678901234567890"? now, how come that be true at all? This: "b = a;" is a bitwisecopy, right? Well, anyway, in this case it could be assumed, that our strings a.text and b.text internally point to the same mem location and changing one of them will affect the other one. Let's test it -- a.text = ""; nah, bad assumption, b.text = "12345678901234567890". Ok, the question here is: "How does std::string know of the assignment operation "b = a;" ?" I'm all lost here... There's something that I have no solution for, the following code gives me mem leak of 32 bytes in vs7.1: struct testObj { std::string text; }; void InitStr( testObj &a ) { testObj b; b.text = "12345678901234567890"; // //b.text = "123456789012345"; -- works fine, I guess //is't due to some internal (16 bytes?) string //buffer, that is used for short strings. short //string optimization, I guess // a = b; } int main() { testObj test; InitStr( test ); return 0; } I've got no idea how to solve this little puzzle...