|
-
January 31st, 2005, 08:39 PM
#1
Pointers, STL....Help
Hi !,
Any help here would be greatly appreciated. What I have is a STL vector, named "people", that has been populated with my own user defined Class "Person".
I now wish to create an array of pointers, named "firstGroup", to a select few elements within the STL vector. With the last person to be specified by name
void Group::selectGroup()
{
for(int i = 0 ; i < 10 ; i++)
{
firstGroup[i] = &people[i];
}
firstGroup[9] = getPerson("Fred"); // ERROR OCCURS HERE
}
Person* Group::getPerson(string surname)
{
vector<Person>::iterator it;
for(it = people.begin(); it != people.end(); it++)
{
if(it->getName() == surname)
{
return it;
}
}
return NULL;
}
This all compiles OK except there is a segmentation fault when I include the line where the error occurs. I figure it must be the getPerson method but where?
thanks
ham
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|