我在用 C++ 编译时遇到问题。请帮助我!
测试.cpp
#include <gtest/gtest.h>
#include "../PayRoll/AddSalariedEmployee.h"
#include "../PayRoll/Employee.h"
class GregorianCalendar;
class PayrollTest : public ::testing::Test {
protected:
virtual void TearDown() {
}
virtual void SetUp() {
}
public:
PayrollTest() : Test() {
int emId = 1;
AddSalariedEmployee t(emId, "Bod", "Home", 1000.00);
t.Execute();
}
GregorianCalendar* gregorian_calendar;
};
TEST(PayrollTest, check_name_employee) {
Employee* e = GpayrollDatabase.GetEmployee(1);
EXPECT_EQ("Bob", e->GetName());
}
AddSalariedEmployee.h
我认为这个文件有问题
//
// Created by lngo9 on 11/24/2017.
//
#ifndef PAYROLL_ADDSALARIEDEMPLOYEE_H
#define PAYROLL_ADDSALARIEDEMPLOYEE_H
#include "AddEmployeeTransaction.h"
#include <string>
using namespace std;
class AddSalariedEmployee : public AddEmployeeTransaction {
public:
virtual ~AddSalariedEmployee();
AddSalariedEmployee(int empid, string name, string address, double salary);
PaymentClassification* GetClassification() const;
PaymentSchedule* GetSchedule() const;
private:
double itsSalary;
};
#endif //PAYROLL_ADDSALARIEDEMPLOYEE_H
AddSalariedEmployee.cpp
//
// Created by lngo9 on 11/24/2017.
//
#include "AddSalariedEmployee.h"
#include "SalariedClassification.h"
#include "MonthlySchedule.h"
AddSalariedEmployee::~AddSalariedEmployee() {
}
AddSalariedEmployee::
AddSalariedEmployee(int empid, string name, string address, double salary)
: AddEmployeeTransaction(empid, name, address)
, itsSalary(salary){}
PaymentClassification*
AddSalariedEmployee::GetClassification() const {
return new SalariedClassification(itsSalary);
}
PaymentSchedule* AddSalariedEmployee::GetSchedule() const {
return new MonthlySchedule();
}
AddEmployeeTransaction.h
//
// Created by lngo9 on 11/24/2017.
//
#ifndef PAYROLL_ADDEMPLOYEETRANSACTION_H
#define PAYROLL_ADDEMPLOYEETRANSACTION_H
#include "Transaction.h"
#include "PayrollDatabase.h"
#include <string>
using namespace std;
class PaymentClassification;
class PaymentSchedule;
extern PayrollDatabase GpayrollDatabase;
class AddEmployeeTransaction : public Transaction {
public:
virtual ~AddEmployeeTransaction();
AddEmployeeTransaction(int empid, string name, string address);
virtual PaymentClassification* GetClassification() const = 0;
virtual PaymentSchedule* GetSchedule() const = 0;
virtual void Execute() = 0;
private:
int itsEmpid;
string itsName;
string itsAddress;
};
#endif //PAYROLL_ADDEMPLOYEETRANSACTION_H
AddEmployeeTransaction.cpp
//
// Created by lngo9 on 11/24/2017.
//
#include "AddEmployeeTransaction.h"
#include "HoldMethod.h"
#include "Employee.h"
class PaymentMethod;
class PaymentSchedule;
class PaymentClassification;
AddEmployeeTransaction::~AddEmployeeTransaction() {
}
AddEmployeeTransaction::
AddEmployeeTransaction(int empid, string name, string address)
: itsEmpid(empid)
, itsName(name)
, itsAddress(address){}
PaymentClassification* AddEmployeeTransaction::GetClassification() const {}
PaymentSchedule* AddEmployeeTransaction::GetSchedule() const {}
void AddEmployeeTransaction::Execute() {
PaymentClassification* pc = GetClassification();
PaymentSchedule* ps = GetSchedule();
PaymentMethod* pm = new HoldMethod();
Employee* e = new Employee(itsEmpid, itsName, itsAddress);
e->SetClassification(pc);
e->SetSchedule(ps);
e->SetMethod(pm);
GpayrollDatabase.AddEmployee(itsEmpid, e);
}
交易.h
//
// Created by lngo9 on 11/24/2017.
//
#ifndef PAYROLL_TRANSACTION_H
#define PAYROLL_TRANSACTION_H
class Transaction {
public:
virtual void Execute();
};
#endif //PAYROLL_TRANSACTION_H
构建时出现错误: 错误:无法将变量“t”声明为抽象类型“AddSalariedEmployee” AddSalariedEmployee t(emId, "Bod", "Home", 1000.00);
请帮帮我!非常感谢!
我是一名优秀的程序员,十分优秀!