If you are forced to use std::list<T*> myList;and let them say it Tis defined as:
struct T
{
T(const char* cstr) : str(cstr){ }
std::string str;
};
then just use std::list::frontto access the first element:
std::string firstStr = myList.front()->str;
, myList.front() , . , , .
NULL: , , . , , , , , ( , std::list<T> over std::list<T*> , ).
, NULL . , , , , , undefined. , std::list NULL, , , .
, , , , , :
std::list<T*> myList;
myList.push_back(new T("one"));
myList.push_back(new T("two"));
myList.push_back(new T("three"));
myList.push_back(new T("four"));
while (!myList.empty())
{
T* pT = myList.front();
myList.erase(myList.begin());
std::cout << pT->str.c_str() << std::endl;
delete pT;
}
:
std:: list ?
std:: list:: ?