我花了好几个小时研究并试图弄清楚为什么我得到这个错误。基本上,与继承有关的三个文件是CollegeMember.h,Employee.h和EmpAcademicRecord.h。雇员。从CollegeMember.h继承,EmpAcademicRecord.h从Employee.h继承。 Like this 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 2012-04-10 02:53:42
感谢您的快速反馈!我实际上尝试过,devC++似乎冻结了。在一个不同的尝试中,我把#include“Employee.h”放在EmpAcademicRecord类中,然后把#include“EmpAcademicRecord.h”放在主要的.cpp文件中(我应该包含这个文件),并且它摆脱了错误。再次感谢! – user1323056 2012-04-10 02:56:19
因此,“可能是一件简单的事情”的评论,但我会添加到答案。 – paxdiablo 2012-04-10 02:57:10