The first and foremost important thing while using C++ is, do not use
arrays. It's a lot better to use a vector if at all you want use an
array for any functionality. This is being stressed by the inventor
himself.
Have something like:
std::vector<Person *> m_vecPerson;
to contain a list of Persons (i.e; Students and Teachers). Provide two
iterators like:
typedef std::vector<Person *>::const_iterator const_person_iterator;
typedef std::vector<Person *>::iterator person_iterator;
These iterators will be useful to traverse the vector of Persons.
In the List class you can functions like:
List::AddPerson(Person * person)
{
m_vecPerson.push_back(person);
}
List::RemovePerson(Person * person)
{
person_iterator result =
std::find(m_vecPerson.being(),m_vecPerson.end(),pe rson);
if(result != m_vecPerson.end())
{
m_vecPerson.erase(person);
}
}
Similarly you can add the other functions also. Now in your menu, you
can have a reference to the List.
Hope this helps.
Thanks,
Kalyan.
mums_se@yahoo.se (Tommy Lang) wrote in message news:<78dde37d.0312081544.527c9e64@posting.google. com>...[color=blue]
> I am working on this project and I need some help/pointers/comments to
> get me started, I am stuck.
> The program will be used to store information in an array while it is
> running.
> I need to store objects of my classes Person(superclass),
> Student(inherit Person), Teacher(inherit Person) in that array.
> The name will be the unique key. These classes are all working ok. I
> want to be able to add, remove, find etc. objects.
>
> To all of this, I have created a menue class to print out a menue on
> the screen for the user where he can select what he wants to do(add,
> remove...) and a class "List" to tie it all together.
> In the menue class I have a reference(List &refList;) to the List
> class and in the listclass I have a pointer to array that will hold
> all the objcts(List *pList[10];).
> I init the reference in the constructor of Menu class like
> menue::menue(const List &L):refList(L){}
>
> Questions:
> When I initiate the object List should I make sure to set all items in
> array to NULL in the constructor ?
> for(int i=0;i<10;i++)
> pList[i]=NULL;
> Can I have only one array ex. List *pList[10]; that can hold all types
> of objects(Person, Student, Teacher)?
> Do I need typecasting to identify objects before adding removing..?
> What methodes would I put in List class? (insert, remove, find, print)
> When I am searching for an object in array, should I return the object
> itself or a pointer to the object?
> In case of returning a pointer, how do I return a pointer to the
> object I am searching for?
>
>
> Thankful for any help
>
> /Tommy[/color]