Ham266
January 31st, 2005, 07:39 PM
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
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