Thanks all for the answers.
I'm sorry but I still have a question.
Let we have following situation.
As wrote Paul McKenzie we add objects to the list, not a pointers:
Since the object m was defined in main function it becomes not valid out of the scope of main. Let MyFunction is called from another thread. What will be if I want to get the object from global g_MyStructList list?Code:#include <list> std::list<MYSTRUCT> g_MyStructList; //... int main() { MYSTRUCT m; g_MyStructList.push_front( m ); // No need for delete // ... }
The synchronization of access the same global list from different threads is out of the scope of my question. I just want to know: Is *itr a valid MYSTRUCT object or it does not?
Thank you.Code:void MyFunction() // called from different thread { std::list<MYSTRUCT>::iterator itr = g_MyStructList.begin(); // Is *itr a valid MYSTRUCT object? // ..... }




Reply With Quote