//-----------------------------------
//Father.h
//-----------------------------------
#ifndef HEADER_FATHER
#define HEADER_FATHER
#include"Bate.h"
#include<iostream>
//-----------------------------------
class Father : virtual protected Base{
public:
Father(){ std::cout<<"Father is created.\n"; }
using Base::driveACar;
void working(){ std::cout<<"Father: "; repairTVSet(); }
};//---------------------------------
#endif //HEADER_FATHER
//-----------------------------------
//Mother.h
//-----------------------------------
#ifndef HEADER_MOTHER
#define HEADER_MOTHER
#include"Bate.h"
#include<iostream>
//-----------------------------------
class Mother : virtual protected Base{
using Bate::doMannulWork;
public:
Mother(){ std::cout<<"Mother is created.\n"; }
using Base::singSongs;
void working(){ std::cout<<"Mother: "; doMannulWork(); }
};//---------------------------------
#endif //HEADER_MOTHER
小孩要继承父母类,而且是无条件全部继承。见如下代码:
//-----------------------------------
//Son.h
//-----------------------------------
#ifndef HEADER_SON
#define HEADER_SON
#include"Father.h"
#include"Mother.h"
#include<iostream>
//-----------------------------------
class Son : public Father, public Mother{
public:
Son(){ std::cout<<"Son is created.\n"; }
using Base::playPingPong;
using Father::repairTVSet;
};//---------------------------------
#endif //HEADER_SON