I have this bit of code:
cerr << client->inventory.getMisc().front()->getName() << endl;
vector<itemPtr>::iterator it;
it = client->inventory.getMisc().begin();
cerr << (*it)->getName() << endl;
Let me explain a little:
clientis that tr1::shared_ptrwhich points to an object that has a member with a name inventorythat has a private element vector<itemPtr>accessible by getMisc(). itemPtris a typedef for tr1::shared_ptr<Item>, and getName()returns a private std::stringmember Item.
Essentially, it client->inventory.getMisc()comes down to std::vector, and I'm trying to get an iterator to its first element.
The problem is that the fourth line is segfaults. Apparently, either the iterator or shared_ptr that it points to is invalid. I used the first cerr instruction to check if the vector itself really is and it prints properly, so I think it is.
Is there something I'm doing wrong? Alternatively, what would you do to debug this?
source
share