#include <iostream>#include <string.h>using namespace std; void eat(){ cout<<"具有吃的能力。"<<endl; }; void work(){ cout<<"具有工作的能力。"<<endl; };class Person{public: Person(); ~Person(); string name; int age; void eat();};Person::Person(){cout<<"Person()"<<endl;}Person::~Person(){cout<<"~Person()"<<endl;}class Worker:public Person{ Worker(); void work();};Worker::Worker(){ cout<<"Worker()"<<endl; }int main(){ Worker *p=new Worker(); delete p; p=NULL;}
1 回答
asd8532
TA贡献143条经验 获得超187个赞
class Worker:public Person{ public://不添加public默认的是private, Worker *p=new Worker();这样就是错的啊 Worker(); void work(); };
- 1 回答
- 0 关注
- 1163 浏览
添加回答
举报
0/150
提交
取消