
March 21st, 2005, 07:52 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 1
Time spent in forums: 14 m 46 sec
Reputation Power: 0
|
|
|
newbie clueless about iterators
There is absolutely nothing clever or difficult about this code: it is one of those student things where you implement a structure of staff which then generates a list later.
I have this so far:
(well, obviously, there's more than that, but this is the bit which doesn't work)
Code:
string Table::toString()
{
if (table.size() < 1)
return "There are no staff records at the moment.";
string str;
//iterate through
vector<Staff*>::iterator iter;
for (iter = table.begin();iter != table.end(); ++iter) {
Staff * tmp = *iter;
str += tmp->toString();
}
return str;
}
where each of the Staff pointers in the list points too an object derived from a base class called Staff.
All nice and simple, what could go wrong? For some reason, when it runs the
Code:
str += tmp->toString();
line, which is a function in the base class only, it crashes out. Painstaking research suggests to me that this is caused by a memory access exception. i can't remember the exact phrase as i have been working on it for 7 hours and can't think straight. This must be some stupid newbie mistake somewhere which looks really obvious to experienced programmers. Does anyone see it yet?
|