我有两个.h文件和一个.cpp文件。当我编译.cpp文件时,它会导致错误:
错误:“雇员”尚未声明
虚拟无效提示(Employee&a)= 0;
这使我感到困惑,因为我在文件中包含#include“ employee.h”。
我已经尝试过更改#include语句的顺序,但这并没有改变。
employee.h:
#ifndef EMPLOYEE
#define EMPLOYEE
#include "insurance.h"
#include <string>
#include <vector>
class Employee
{
public:
bool quit;
std::string name;
float basesalary, commission, totalsalary;
std::vector<Insurance*> sales;
float ComputeSalary();
virtual float ComputeCommission() = 0;
virtual void Prompt() = 0;
};
#endif
employee.cpp:
#include "employee.h"
float Employee::ComputeSalary()
{
totalsalary = basesalary + commission;
return totalsalary;
}
insurance.h:
#ifndef INSURANCE
#define INSURANCE
#include <string>
#include "employee.h"
class Insurance
{
public:
std::string name, type;
float commission;
virtual float ComputeCommission() = 0;
virtual void Prompt(Employee &a) = 0; // source of error!
};
#endif