std::string: Has my compiler gone nuts??
To the Pros out there:
Hy, im searching for a bug since 2 days, and i asked a lot of pros in my company, but nobody could help me.
Heres the situation:
Visual Studio Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600)
I had a project with a strange bug, so i could melt down the problem into this simple program (I took the original Project and
deleted file after file to look when it would go correctly) and still got the strange behaviour.
heres the whole program, its a .vcproj-file project with 1 source file called main.cpp where the following is inside:
Code:
#include <string>
class EventTest
{
public:
EventTest (int a_id, const std::string& a_text);
int m_Id;
std::string m_Text;
};
/*inline*/ EventTest::EventTest (int a_id, const std::string& a_text)
: m_Id(a_id)
, m_Text(a_text)
{
//m_Id = a_id;
//m_Text = a_text;
}
int main(int argc, char** argv)
{
EventTest test(1, "Text");
//std::string strTest = "TEST";
return 0;
}
there are also some additional Dependencies in the Properties, but i wont mention it here.
The result when debugging it is extremely strange. its about the content of m_Text who is (watched with debugger) always
something like "0,0,0,0,T,e,x,t,-b,4,0,0,0,d,4,....." (and signs i cant write here) and so on with a string size of _MySize = 14220893!! instead of 4.
As soon as i use a variable of type std::string (the line that is commented now) all works fine!!!
I can make the behaviour the other way round as well: make the constructor inline, or initialize the members in the body. when doing either of the two, then the program works only correct (having "Text" in the string) when NOT having the variable of type std::string in the code!!
I made an other new project (not deleting things from the original project) with exactly the same code, the same project settings, and the same Dependencies. And this program is ALWAYS working correctly!!! but i cant find any difference, its like magic.
also the output (wich dlls are loaded) is the same.
The program would acctually work finde only this std::string in the class is nasty!
Does anybody has an idea? or a tipp how to analyze the problem further??
Im sure it is some strange sideeffect, but of what??
thanx for any input!
andreas
what fails is initialisation
The problem occurs right directly after initialisation of the object (after the only line, this class is used). i tryed rebuild, clean etc many many times before, but it does not help. how can this strange behaviour of (only) the std::string class be influenced?
thanx
I think i found the problem, but why?
Hello, i just realised, that when i delete the file vc80.idb (minimum rebuild dependency File)
in the same folder as the .vcproj file is, the thing is working correctly!! in all my experiments i always copied the whole project and changed it, so i also copied the vc80.idb, wich is not deleted after a rebuild all.
But i also found out, that the problem can occur again, and then i have to delete the file again.
any clue what the reason can be?
andreas