我在C++中编译时遇到问题。请帮我!

测试文件

#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);

}

Transaction.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);

请帮我!非常感谢!

最佳答案

AddSalariedEmployeeAddEmployeeTransaction的子代,= 0是抽象类(您在某些方法的主体中使用{})。
由于这些方法未在派生类中定义,因此派生类仍然是抽象的,无法实例化。

您需要定义(实现)所有抽象方法(即使您仅给它们一个空的主体ojit_code)也可以实例化子类。

10-08 03:54