#include<iostream>
#include<string>
#include<queue>
#include<stdexcept>//标准异常库
using namespace std;
//猫狗队列
//在C++中,类是不能加权限修饰符的,只有类的成员或者继承的时候才能加。
//这里是public继承,意思是Pet中所有的访问权限在Dog中不变,如果是peivate继承,那么是说Pet中的所有成员变成Dog的私有成员。
//在子类的构造函数中调用父类的有参构造函数就是下面这么用Cat():Pet("Cat"){};
class Pet
{
private:
string type;
public:
Pet(string type){
this->type = type;
}
Pet(){}
string getPetType(){
return this->type;
}
};
class Dog: public Pet
{
public:
Dog():Pet("dog"){}
};
class Cat: public Pet
{
public:
Cat():Pet("cat"){}
};
/************************以上为题目给出原始接口***********************/
//使用一个带时间戳的Pet类区分猫狗的进入顺序
class PetTimeStamp
{
private:
Pet myPet;
long timeStamp;
public:
//构造函数后面加了:是初始化列表,初始化myPet为p
PetTimeStamp(Pet p, long count):myPet(p){
this->timeStamp = count;
}
Pet getPet(){
return myPet;
}
long getTimeStamp(){
return time
c++——猫狗队列
最新推荐文章于 2024-01-03 05:00:00 发布