#ifndef PERSON_H #define PERSON_H #include #include //Things needed in reading/writing from/to file. #include #include using namespace std; //---------- class Person //---------- { public: static const string classID; //This is used for identifying the type in the savefile. Note that the type is common //for all objects of type Person, so it is made static(meaning that regardless of the //number of Person objects in the program, there is only one classID string. //static members must be defined outside the class - done in person.cpp protected: string name; //Name of the person. virtual void PrintToFile(ostream& o, bool printClassID = true) const; //Used for printing object to file. virtual void ReadFile(ifstream& in); //This method is used when reading data from file. After a class identifier string has //been read and if it is 'known' class, then that classes ReadFile()-method gets called. public: Person() : name("No name") {}; Person(const string& aName) : name(aName) {} virtual ~Person() {}; //Rule of thumb: If a class has virtual function(s), then make the //destructor virtual. static void SaveToFile(vector& cont, const string& filename = "data.txt"); static unsigned int LoadFromFile(vector& cont, const string& filename = "data.txt"); //Returns the number of objects loaded. static void ClearContainer(vector& cont); //Note: In the above functions the container type is specified to be vector, even thought //it could be for example list as well. virtual void Print(bool printClassID = true) const; //Used in printing the objects on screen. }; #endif