Declaring an array of objects of a class
Our C++ professor assigned a group project that requires us to create an addressbook style program. The program must ask the user to input a person's contact information (ie. Name, address, email, phone#) and store them in a list that can be sorted, searched, and printed to the console. We have everything working, except for the part where we store more than one contact. We have two classes, one in which the user inputs the data (class Person), and another that saves, searches, and sorts that data (class List). At this point in our development, our logic says that each new person entered into the addressbook will be stored as an Object of one of our classes. We would like to accomplish this by declaring an array of objects of class person inside class list. We are receiving a compiler error relating to the data type of our array. Any Ideas?
Code:
//Module Revied Nov 21, 2011: NDA
#ifndef LIST_H
#define LIST_H
#include <string>
#include "Person.h"
#include "List.h"
using namespace std;
/* An object of this class will be an array which stores a list of contacts that the user has entered. The entire list will be saved to disk. This class will define functions to search the list and print it to the console.*/
//The number of constants stored is 100 for now. can be changed.
const int MAX_PEOPLE = 100;
class List
{
private:
int numContacts;
int nextEmptySpot();
Person contactArray[MAX_PEOPLE]; //Line returns 3 errors
public:
//code continues, deleted to shorten. all other code produces no //errors
We cannot seem to make the computer recognize Person as a valid data type, even thought it is the name of our other class, and we have included it's header file. Any ideas on how to fix this array?