//Person类的定义
#ifndef PERSON_H_
#define PERSON_H_
using namespace std;
#include <string>
class Person{
public:
Person(string name);
virtual ~Person();
virtual void work() = 0;
protected:
string m_strName;
};
#endif//Person类的实现
#include "Person.h"
#include <iostream>
Person::Person(string name)
{
m_strName = name;
cout << "Person()" << endl;
}
Person::~Person()
{
cout << "~Person" << endl;
}//Worker类的定义
#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//Worker类的实现
#include"Worker.h"
#include <iostream>
Worker::Worker(string name,int age) :Person(name)
{
m_iAge = age;
cout << "Worker()" << endl;
}
Worker::~Worker()
{
cout << "~Worker" << endl;
}//Dustman类的定义
#ifndef DUSTMAN_H_
#define DUSTMAN_H_
#include "Worker.h"
class Dustman :public Worker
{
public:
Dustman(string name,int age);
~Dustman();
virtual void work();
};
#endif//Dustman类的实现
#include "Dustman.h"
#include <iostream>
Dustman::Dustman(string name, int age) :Worker(name,age)
{
cout << "Dustman()" << endl;
}
Dustman::~Dustman()
{
cout << "~Dustman" << endl;
}
void Dustman::work()
{
cout << "work()" << endl;
}//main函数
#include <iostream>
#include "Dustman.h"
#include <stdlib.h>
using namespace std;
int main(void){
Dustman persn("jin",20);
system("pause");
return 0;
}编译可以通过,但运行就会报错,下面是所有的错误提示,点击错误提示不能提示是哪一行出错了,所以搞不明白哪儿错了警告 1 warning LNK4042: 对象被多次指定;已忽略多余的指定 E:\visual studio 2013\Projects\test\test\Debug\Dustman.obj 1 1 test警告 2 warning LNK4042: 对象被多次指定;已忽略多余的指定 E:\visual studio 2013\Projects\test\test\Debug\Person.obj 1 1 test错误 3 error LNK2019: 无法解析的外部符号 "public: __thiscall Dustman::Dustman(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (??0Dustman@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z),该符号在函数 _main 中被引用 E:\visual studio 2013\Projects\test\test\demo.obj test错误 4 error LNK2019: 无法解析的外部符号 "public: virtual __thiscall Dustman::~Dustman(void)" (??1Dustman@@UAE@XZ),该符号在函数 _main 中被引用 E:\visual studio 2013\Projects\test\test\demo.obj test错误 5 error LNK1120: 2 个无法解析的外部命令 E:\visual studio 2013\Projects\test\Debug\test.exe test
1 回答
- 1 回答
- 1 关注
- 1475 浏览
添加回答
举报
0/150
提交
取消