域操作符::
基类为Animal,子类为Fish
Animal.h
#include"stdafx.h"
class Animal
{
public:
Animal(int height, int weigh);
~Animal();
void eat();
void sleep();
virtual void breath();
}:
Animal.cpp
#include"stdafx.h"
#include"iostream.h"
using namespace std;
#include"Animal.h"
Animal::Animal(int height, int weigh)
{
}
Animal::~Animal()
{
}
void Animal::eat()
{
cout<<...<<endl;
}
void Animal::fish()
{
cout<<...<<endl;
}
void Animal::breath()
{
cout<<...<<endl;
}
Fish.h
#include"stdafx.h"
class Fish : public Animal
{
public:
Fish();
~Fish();
void breath();
};
Fish.cpp
#include"stdafx.h"
#include"iostream.h"
using namespace std;
#include"Animal.h"
#include"Fish.h"
Fish::Fish() : Animal(400,300)
{
};
Fish::~Fish()
{
};
void Fish::breath()
{
cout<<...<<endl;
};
MAIN
#include"stdafx.h"
#include"iostream.h"
using namespace std;
#include"Animal.h"
#include"Fish.h"
void fn(Animal *pAn)
{
pAn->breath();
}
int _tmain(int argc, _TCHAR* argv[])
{
Fish fi;
Animal *pAn;
pAn = &fi;
fn(pAn);
}