Hi I have a problem using a class member deque <task *> m_queued_tasks that contains pointers to a struct. I try to insert new structs in the deque but when the program goes out of scope from where the new struct was created, the values in the deque gets messed up. I cannot figure out what is wrong. The class:
The problem was that I allocated memory for the char (line 1) char * l_id = newchar[40], but then didn't use the allocated memory. c_str() (line 3) returns a const char * which points to an internal location with the required storage space for this sequence of characters plus its terminating null-character, but the values in this array should not be modified in the program and are only granted to remain unchanged until the next call to a non-constant member function of the string object.
So, I instead copied this allocated memory to my allocated memory by replacing line 3 with memcpy(): memcpy(l_id, a_command[1].c_str(), DEFAULT_ID_LEN) and everything worked perfectly.