我花了好幾個小時研究並試圖弄清楚爲什麼我得到這個錯誤。基本上,與繼承有關的三個文件是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