为什么我在使用此代码编译时会出现错误?
#ifndef OPERATOR_H
#define OPERATOR_H
#include <cstdlib>
#include <iostream>
#include <string>
#include "Individual.h"
using namespace std;
class Operator
{
public:
Operator();
virtual void execute (Individual* parent);
private:
};
#endif
然后在cpp文件中我有
#include <cstdlib>
#include <iostream>
#include <string>
#include "Operator.h"
using namespace std;
Operator::Operator()
{
}
void execute(Individual* parent)
{
}
答案 0 :(得分:0)
定义析构函数。具有虚方法的类的vtable是在定义构造函数的转换单元中创建的。
在标题中,添加:
virtual ~Operator();
在源文件中,添加:
Operator::~Operator() {
}