szreport is an array local to the function. When the function returns, it goes out of scope ( and it's memory is automatically freed )
You are returning the address of that array which, after the function ends, will point to an invalid loacation
You can either allocate szreport with new/malloc or use a std::string
or just use a string so you don't have to worry about overflowing the buffer / freeing the memory / etc.
1 2 3 4 5 6 7 8 9 10 11 12 13
// see how much easier this is?
// it's also much, much safer and has no risk of memory leaks
string Evaluation::show()
string szreport;
string szValue;
szreport = "\n*****************************\n\tvalue:\t";
szreport += value;
szreport += "\n\tdescription\t";
szreport += getDescription();
return szreport;
}
Disch (3172) Link to this post Sep 10, 2010 at 8:09pm
how are you serializing the char array?
Odds are the string can be serialized the same way (or at least very similar)
using boost.Anyway I don't have the time to convert my entire program to a string version.Ii's 1000 lines of code.Please tell me about deleting after Newing it.it's less costly.