Я провел немало часов, исследуя и пытаясь понять, почему я получаю эту ошибку. В основном три файла, которые связаны с наследованием, это CollegeMember.h, Employee.h и EmpAcademicRecord.h. Наемный рабочий. наследуется от CollegeMember.h и EmpAcademicRecord.h наследуется от Employee.h. Как этот CollegeMember < - Сотрудник < - EmpAcademicRecord. Ошибка возникает в EmpAcademicRecord.h. Вот три файла.ожидаемое имя класса перед '{' токеном. Наследование C++
CollegeMember.h
#include <cstdlib>
#include <iostream>
#include<ctype.h>
#include<string.h>
#include "Employee.h"
#include "Student.h"
using namespace std;
// ****************************************************************************
// Class Definitions follow
typedef char* String;
// The CollegeMember class
class CollegeMember
{
protected:
int ID_Number;
string FirstName, LastName;
string AddressLine1, AddressLine2, StateProv, Zip;
string Telephone;
string E_Mail;
string answer, answer2, answer3, answer4;//used as sort of booleans for use with validation
// member functions
public:
CollegeMember (); // constructor
CollegeMember(const CollegeMember&); //overloaded constructor
void Modify (CollegeMember Member);
void InputData(int x);
string Summary (); //summary
string PrintMe(); //fully describes
}; // End of CollegeMember class declaration
Employee.h
#include <cstdlib>
#include <iostream>
#include<ctype.h>
#include<string.h>
#include "EmpAcademicRecord.h"
#include "EmpEmploymentHistory.h"
#include "EmpExtraCurricular.h"
#include "EmpPersonalInfo.h"
#include "EmpPublicationLog.h"
using namespace std;
// ****************************************************************************
// Class Definitions follow
typedef char* String;
// The Employee Class
class Employee: protected CollegeMember
{
float Salary;
protected:
string Department, JobTitle;
// Member Functions
public:
Employee (); // constructor
void Modify (Employee ThisEmp);
void InputData(int x);
void SetSalary (float Sal) // Specified as an in-line function
{ Salary = Sal;}
float GetSalary () {return Salary;} // Specified as an in-line function
string Summary (); //summary
string PrintMe(); //fully describes
}; // End of Employee class declaration
EmpAcademicRecord.h
#include <iostream>
#include <cstdlib>
#include<ctype.h>
#include<string.h>
using namespace std;
typedef char* String;
class EmpAcademicRecord: protected Employee{ //error occurs on this line
protected:
int ReferenceNumber;
string Institution;
string Award;
string start;
string end;
public:
EmpAcademicRecord();
void InputData (int x);
void Modify(EmpAcademicRecord ThisRec);
void Summary();
};
Любая помощь с этим было бы весьма признателен.
Если вы включите «employee.h», вам придется помещать защитники заголовков, так как «employee.h» включает этот файл. – chris
Спасибо за обратную связь! Я действительно пробовал это раньше, и devC++ просто замерз. В другой попытке я помещаю #include «Employee.h» в класс EmpAcademicRecord, а затем помещаю #include «EmpAcademicRecord.h» в основной файл .cpp (который должен был включить), и он избавился от этой ошибки. Еще раз спасибо! – user1323056
Следовательно, комментарий «может быть простым», но я добавлю это к ответу. – paxdiablo