Well, I was trying to please VS2013 compiler, when I began to try this code:
CString::CString(double pDouble)
: buffer(0), buffc(0), sizec(0), readc(0), writec(0)
{
char tempBuff[32];
sprintf_s(tempBuff, 32, "%f", pDouble);
*this = tempBuff;
}
Ok, it was sprintf_s(tempBuff, “%f”, pDouble); before I changed it to sprintf_s …
Anyway, this looks very weird to me.
If I look at the end of CString class in the .h file:
[CODE] inline unsigned int readGUInt4();
inline unsigned int readGUInt5();
protected:
char *buffer;
int buffc, sizec, readc, writec;
};[/CODE] I can begin to guess that this points to the CString Object, *this is said to be not the object but a copy of it according to: http://stackoverflow.com/questions/2750316/this-vs-this-in-c and I can guess that (*this).buffer is equivalent to *this because buffer is the first defined thing in CString object… but where I have problem… from C is tempbuffer defined on the stack? Then how come we use that like if it was a dynamic allocated region like malloc gives? I would expect that memory to disappear from memory at any point.
Return *this returns a copy. The code you posted doesnt return anything. I really cant say more because I have no fucking clue what you are even trying to ask.
Edit: it looks like you are performing an operation on that dereferenced pointer. So you are actually editing the current object instead of making a copy.
I am not convinced the original code is correct. It looks like it try to make buffer points to a temporary value, which seems wrong. That said, I am pretty newbie on C++.