1新建anmial.h文件:
#ifndef ANIMAL_H
#define ANIMAL_H
class animal{
public:
animal();
void eat();
void sleep();
private:
};
#endif
2新建fish.h文件:
#ifndef FISH_H
#define FISH_H
#include"animal.h"
class fish :public animal{
public:
fish();
void show();
};
#endif
3新建anmial.cpp文件:
#include"animal.h"
#include<iostream.h>
void animal::eat(){
cout<<"animal eat"<<endl;
}
void animal::sleep(){
cout<<"animal sleep"<<endl;
}
animal::animal(){}
4新建fish.cpp文件:
#include<iostream.h>
#include"fish.h"
#include"animal.h"
fish::fish(){}
void fish::show(){
cout<<"fish show"<<endl;
}
5新建main.cpp文件
#include"animal.h"
#include"fish.h"
#include<iostream>
using namespace std;
int main(){
animal a;
a.eat();
a.sleep();
cout<<"****************"<<endl;
fish ff;
ff.eat();
ff.sleep();
ff.show();
return 0;
}