"solarin" <en.navarro@gmail.comskrev i meddelandet
news:1156504936.345976.129040@75g2000cwc.googlegro ups.com...
peter koch ha escrito:
Quote:
Quote:
>your original post was misleading. In this case the error is likely
>inside the msgToLogger class.
>>
>/Peter
>
>Ok, my fault. Let me start again.
>
>In class A, Išve declared a string in A.h (myString). The class A,
>has
>a method that call another class and a string is returned.
>
>A::StringToLogger(CMessage *msg)
>{
myString = msg->GenerateString();
>}
>
>This code fails when the program tries to put the result of
>"msg->GenerateString()" into myString. (myString is declared in A.h)
>
>but if I do the following,
>
>A::StringToLogger(CMessage *msg)
>{
string myString // new declaration of myString.
myString = msg->GenerateString();
>}
>
>It runs ok.
>
>The question is: Why I need to declare the string again?
You don't declare the string again, this is an entirely new string.
Unfortunately it is destroyed again at the end of the function. It
indicates that the msg parameter might be ok, though.
So the next question is: What does the declaration of the real
myString look like? Is it a std::string, or a CString, or a char*? Is
it static?
Is it perhaps damaged somewhere else in the code?
Bo Persson