繁体   English   中英

C ++派生类继承方法错误

[英]C++ Derived Class Inheritance Method Error

自从我用C ++编程以来已经有一段时间了,我试图做一些练习问题以再次熟悉语法。 我正在写有一个基类节目RetailEmployee 3派生类: SalesEmployeeWarehouseEmployeeManagerEmployee 我的派生类之一的标头顶部有以下代码:

// Sales Employee Class Header
#indef SalesEmployee
#define SalesEmployee

#include <stdio.h>
#include "RetailEmployee.h"

using namespace std;

class SalesEmployee
{
public:
    SalesEmployee(string department, float pay, int ID, string name)
.
.
.

但是,每当我尝试在SalesEmployee实例上使用基类中的方法时,都会收到一条错误消息,指出未找到该方法。 另外,所有文件都在同一目录中。

有没有人有什么建议?

您尚未指示编译器class SalesEmployeeclass RetailEmployee 为此,您应该:

class SalesEmployee : public RetailEmployee
{

}

您还需要更改class SalesEmployee的构造函数,以将必要的构造初始化信息传递给class RetailEmployee 在您的SalesEmployee.cpp实现文件中是这样的:

SalesEmployee::SalesEmployee(string department, float pay, int ID, string name) : RetailEmployee( department, pay, ID, name ) 
{
    // Whatever special initialization SalesEmployee has goes here.
}

我假设所有这些数据成员实际上都是在基类中定义的,因为它们对于所有类都是通用的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM