Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法声明变量';t';为抽象类型';增加受薪员工'; 我在C++中有编译问题。请帮帮我_C++_Build_Constructor_Abstract Class - Fatal编程技术网

无法声明变量';t';为抽象类型';增加受薪员工'; 我在C++中有编译问题。请帮帮我

无法声明变量';t';为抽象类型';增加受薪员工'; 我在C++中有编译问题。请帮帮我,c++,build,constructor,abstract-class,C++,Build,Constructor,Abstract Class,Test.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 vo

Test.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());
}
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
//
// 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
交易记录.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
//
// 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” 增加受薪员工t(emId,“董事会”,“家庭”,1000.00)


请帮帮我!非常感谢

AddSalariedEmployee
AddEmployeeTransaction
的子类,它是一个抽象类(您正在使用
=0
作为某些方法的主体)。
由于这些方法没有在dervied类中定义,因此派生类仍然是抽象的,无法实例化


您需要定义(实现)所有抽象方法(即使您只给它们一个空的主体
{}
),以便能够实例化子类。

AddSalariedEmployee
AddEmployeeTransaction
的子类,这是一个抽象类(您正在对某些方法的主体使用
=0

由于这些方法没有在dervied类中定义,因此派生类仍然是抽象的,无法实例化

您需要定义(实现)所有抽象方法(即使只给它们一个空的body
{}
),以便能够实例化子类

//
// 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