C++ 键入对"生产者的 vtable"的未定义引用
C++ Type undefined reference to `vtable for Producer'
我一直收到错误,未定义引用`vtable for Producer'对于我的子类制作人:
#include "Producer.h"
Producer::Producer (unsigned int ID, int age1, std::string name1,
char gender1, std::string jobDescription1)
{IDNumber = ID; age = age1; name = name1;
jobDescription = jobDescription1; gender = gender1;}
void SetJobDescription(std::string description){}
void PrintPersonnel(){cout<<"";}
Producer::~Producer(){}
父级是:
#include <string>
#include <iostream>
class Personnel{
protected:
unsigned int IDNumber;
int age;
std::string jobDescription;
std::string name;
char gender;
public:
virtual void PrintPersonnel() = 0;
unsigned int GetID();
int GetAge();
std::string Getname();
std::string GetjobDescription();
char GetGender();
virtual ~Personnel();
};
//Personel.cpp
#include "Personnel.h"
unsigned int Personnel::GetID(){return IDNumber;}
int Personnel::GetAge(){return age;}
std::string Personnel::Getname(){return name;}
std::string Personnel::GetjobDescription(){return jobDescription;}
char Personnel::GetGender(){return gender;}
Personnel::~Personnel(){}
它有一个纯粹的虚拟功能。为什么我不能实现子类Producer?
非常感谢。
代码中的问题是您忘记了一个成员函数的作用域。尝试:
void Producer::PrintPersonnel(){cout<<"";} // Producer:: was missing
// so you were defining a global function instead
// of a member function.
请注意,您对SetJobDescription()
的定义也有类似的问题。由于它不是一个虚拟函数,它只会将您引向一个未定义的引用。
如果它仍然不起作用,那么您应该将某个地方~Personnel()
定义为注释中建议的某个人。
相关文章:
- 纯虚拟类和错误未定义对 'vtable 的引用
- 对植物的 vtable 的未定义引用?
- 未定义的符号缺少 vtable
- 使用多个命名空间对 vtable 的未定义引用
- 对"车辆的 vtable"的未定义引用 - 面向对象的编程练习
- Qt Quick + CMake + 自定义 QObject 导致对"vtable"的未定义引用
- C++ 未定义对 vtable 异常的引用
- 看起来如此主要的错误.cpp:(.text.startup+0xd6):未定义对"vtable for Counter"的引用?
- 用嵌套类对VTable的未定义引用
- 未定义对 vtable 错误的引用
- 对'vtable for class'的未定义引用
- 奇怪的未定义引用了`vtable
- 构造函数中对"vtable"的未定义引用
- C++ 继承问题:未定义对"vtable"的引用
- 构造函数中对 vtable 的未定义引用
- 在 qt 控制台应用程序中未定义对 'vtable for myObj' 的引用 - 信号和插槽
- 关于vtable符号可能未定义,因为类缺少其键函数
- 访问VTable直接发出未定义的错误
- 对"vtable for "命名空间继承的未定义引用 对"类型信息"的未定义引用
- 对具有继承的 vtable 的未定义引用