哪位大神能帮我看看哪里出现问题了吗?我已经定义子类虚函数了,但还是出现问题
#ifndef PERSON_H #define PERSON_H #include<string> using namespace std; class Person { public: Person(string name); virtual~Person(); virtual void worker() = 0; protected: string m_strName; }; #endif
#include"Person.h"
#include<iostream>
using namespace std;
Person::Person(string name)
{
m_strName = name;
cout << "Person()" << endl;
}
Person::~Person()
{
cout << "~Person()" << endl;
}
#ifndef WORKER_H
#define WORKER_H
#include"Person.h"
class Worker:public Person
{
public:
Worker(string name,int age);
virtual~Worker();
virtual void work();
protected:
int m_iAge;
};
#endif
#include"Worker.h"
#include<iostream>
using namespace std;
Worker::Worker(string name, int age):Person(name)
{
m_iAge = age;
cout << "Worker()" << endl;
}
Worker::~Worker()
{
cout << "~Worker()" << endl;
}
void Worker::work()
{
cout << "work()" << endl;
}
#ifndef DUSTMAN_H
#define DUSTMAN_H
#include"Worker.h"
class Dustman:public Worker
{
public:
Dustman(string name, int age);
virtual~Dustman();
virtual void work();
};
#endif
#include"Dustman.h"
#include<iostream>
using namespace std;
Dustman::Dustman(string name, int age):Worker(name,age)
{
cout << "Dustman()" << endl;
}
Dustman::~Dustman()
{
cout << "~Dustman()" << endl;
}
void Dustman::work()
{
cout << "work()" << endl;
}
#include"Dustman.h"
#include"Worker.h"
#include<iostream>
using namespace std;
int main()
{
Worker worker("zhang", 15);
return 0;
}
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2259 “Worker”: 不能实例化抽象类 dustman d:\visual studio 2015\projects\dustman\dustman\demo.cpp 8
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) 不允许使用抽象类类型 "Worker" 的对象: dustman d:\Visual Studio 2015\Projects\dustman\dustman\demo.cpp 8