T
Tommy Lang
Hi!
I have aa array with pointers to the class(object) Person that I
created
( Person *ptr[10]; ). From class person there are two derived classes,
student and employee. I can add and remove objects of these types in
my array. Now I want to be able to search for a specific object of my
choice based on the persons name. How do I do that?? I need help.
So far this is what I've come up with...
//The class Personlist contains the Person *ptr[10], and functions
//to add/remove objects.
bool Personlist::find(char* name, int & position)
{
bool result = true;
int i = 0;
position = -1;
while(i<number_of_elements)//number_of elements is number of
//objects in array
{
//The Person class have a variable called m_name.
//How can I reach it from here and compare it to what
//name is sent into this function? For now I just want
to
//return true or false (and reference to position).
i++;
}
if(position == -1)
result = false;
return result;
}
Thanks,
Tommy
I have aa array with pointers to the class(object) Person that I
created
( Person *ptr[10]; ). From class person there are two derived classes,
student and employee. I can add and remove objects of these types in
my array. Now I want to be able to search for a specific object of my
choice based on the persons name. How do I do that?? I need help.
So far this is what I've come up with...
//The class Personlist contains the Person *ptr[10], and functions
//to add/remove objects.
bool Personlist::find(char* name, int & position)
{
bool result = true;
int i = 0;
position = -1;
while(i<number_of_elements)//number_of elements is number of
//objects in array
{
//The Person class have a variable called m_name.
//How can I reach it from here and compare it to what
//name is sent into this function? For now I just want
to
//return true or false (and reference to position).
i++;
}
if(position == -1)
result = false;
return result;
}
Thanks,
Tommy