I had to write a program that allows the user to type in information about real estate properties and stores each as a class object. It has a class function that can print all of them out in a formatted way. When I store them as an array of class objects I just increment the [i] and then when I print them out I go back through and index through and print them out. Well now I have to store them as a linked list of objects and I am having problems. Below is the constructor, everything works fine until I try to add a pointer that will link one object to the next (* theLink).
RealEstate::RealEstate(string address, double TotalLivArea,
double TotYardArea,bool IsCondo,bool rentable,
:location(address),TotLivingArea(TotalLivArea), YardArea (TotYardArea),condo(IsCondo),rentable(rentable),li nk(theLink)
When I stored the objects in an array I would get the input from the user and then do this:
estate[i] = property;
Now with the linked list I am trying to do this:
typedef RealEstate* EstatePtr;
head = new RealEstate(locate,TotLiv,YardAre,condo,
With an array I understand that if I increment [i] then the next item will be stored there but when I put a new RealEstate object at the head of the list how do I get the last one to point to the one before it and then how do I index through to print them out (like I do with the array)?