Hi, I'm working on a linked list filled with class objects and I've encountered a weird problem that I cannot see how to resolve. I declare 2 self-referential pointers within my 2 classes and the error:
In file included from prog2.cpp:16:
employeedatalist.cpp: In function âvoid getData(std::fstream&)â:
employeedatalist.cpp:15: error: âheadâ was not declared in this scope
employeedatalist.cpp:19: error: ânextâ was not declared in this scope
Here is the code with the error:
#include <iostream>
#include "employeedatalist.h"
using namespace std;
/**
This function creates an EmployeeDataList Object from a file. This is the linked list to be used!
*/
void getData(fstream& dataFile)
{
int IDnumber, yearsAge; //Placeholder vars for infor from file.
string nameFull, phNumber; // Placeholder vars.
dataFile << IDnumber << nameFull << phNumber << yearsAge;
head = new EmployeeData(IDnumber, nameFull, phNumber, yearsAge);
while (!dataFile.eof())
{
dataFile << IDnumber << nameFull << phNumber << yearsAge;
next = new EmployeeData(IDnumber, nameFull, phNumber, yearsAge);
}
}
RELEVANT CODE
// Class for the linked list.
#include <iostream>
#include <fstream>
#include "employeedata.h"
#ifndef employeedatalist_h
#define employeedatalist_h
using namespace std;
class EmployeeDataList
{
private:
class EmployeeData; //Class data type for nodes.
EmployeeData *head;
public:
EmployeeDataList() //Default empty constructor function.
{
head = NULL;
}
~EmployeeDataList(); //Destructor.
void getData(fstream& dataFile); // Obtain records from file.
void appendRecord(EmployeeData); //Add a record to the end.
void insertRecord(EmployeeData); //Add a record in the middle of the list.
void deleteRecord(EmployeeData); //Delete a record.
void updateRecord(EmployeeData); // Update a record.
void displayRecord(); //Display one user-defined record.
void displayAllRecords(); //Display all records.
void searchData (int);
};
#endif
//Class used for database object.
#ifndef employeedata_h
#define employeedata_h
#include <string>
using namespace std;
class EmployeeData
{
private:
friend class EmployeeDataList;
int id; // Holds ID number of employee.
string fullName; // Holds full name string of employee.
string pNumber; //Holds social security number string of employee.
int age; //Hold employee's age.
EmployeeData *next;
public:
EmployeeData() //Default empty constructor function.
{
}
/**
This function creates an EmployeeData Object from user input.
*/
EmployeeData(int idNumber, string name, string phoneNumber, int years)
{
id = idNumber;
fullName = name;
pNumber = phoneNumber;
age = years;
next = NULL;
}
};
#endif
The MAIN
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "employeedatalist.cpp"
using namespace std;
//Function prototypes.
int main()
{
EmployeeDataList *employeeList = NULL;
fstream dataFile;
dataFile.open("empdb.data", ios::in);
if (dataFile.fail())
cout << "The Neuvelle Database file is missing. Please call server management ASAP" << endl;
employeeList->getData(dataFile);
return 0;
}
Please any help on clearing up this issue? I've looked everywhere for solutions and can't figure it out...