C++派生类继承方法错误
C++ Derived Class Inheritance Method Error
我已经有一段时间没有用C++编程了,我正在尝试做一些练习题来再次熟悉语法。 我正在编写一个程序,该程序具有具有 3 个派生类的基类RetailEmployee
:SalesEmployee
、WarehouseEmployee
和 ManagerEmployee
。 我在其中一个派生类的标头顶部有以下代码:
// 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 SalesEmployee
是 class 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.
}
我假设所有这些数据成员实际上是在基类中定义的,因为它们应该对所有类都是通用的。
相关文章:
- C++:正在检查LinkedList中的回文-递归方法-错误
- C++数组队列实现方法错误
- 方法错误"not all control paths return a value"和方法不返回值
- OpenGL 顶点缓冲区类重定义和模板方法错误
- 如何在 VC++ 中通过引用传递另一个对象的方法(错误 C2664)
- 复数程序编译时的计算方法错误
- CMake 构建错误 - 虚拟方法错误缺少 vtable
- 接受 lambda 作为参数的类方法 - 错误消息
- c++程序方法错误visualstudio
- OpenCV "findContours"方法错误
- std::线程类方法错误
- 基类没有新方法错误
- C++派生类继承方法错误
- 指向类方法错误c++11的指针数组
- 使用jni调用方法:错误的jni oop参数
- QVector.push_back方法错误
- 对静态方法错误的未定义引用
- Friend方法错误
- async_write方法错误
- 重写方法错误C++