Hi, I'm trying to do an e-mail-like program. But I'm having an issue with the date of the "e-mail's". Say, I created an e-mail, if, after that, I create a new one, the date of the oldest one changes.
This is my Message class constructor and private fields:
Usually the m_ prefix is used for member variables but you use it for function parameters instead. Oh well, I don't care, I just felt like pointing it out in case made it by mistake.
I think the problem is that localtime returns a pointer to a static internal tm object. When localtime is called a second time it will reuse the same object it used the first time, change it and return the same pointer to it. All Message::date pointers will point to the same object so that is why you get the same output.
And thanks on the actual problem, that makes sense. I'll try changing it in a second.
[EDIT]:
Problem Solved! Here is the changes I did to the code:
-to the private fields: struct tm date;
-to the constructor: date=*localtime(&d_raw);
-to the tests: strftime (strng,18,"%c",&(msg2.getDate()));
Once again, thanks for the help!
About the prefixes, I don't use them myself but the assignment would look like this: m_subject = subject; and I don't think there is any point in using this-> here.
If you initialize the variables in the constructor initialization list (which I recommend you do if possible) it doesn't matter so much if parameters and member variables have the same names.