|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <string>
class Pet
{
public:
std::string petname;
static int getcount(void);
Pet(std::string petname);
~Pet();
private:
static int count;
};
Pet::Pet(std::string petname)
{
this->petname = petname;
std::cout << "成功诞生了一只" << petname << std::endl;
count++;
}
Pet::~Pet()
{
count--;
}
int Pet::getcount(void)
{
return count;
}
//''''''''狗 Dog
class Dog:public Pet
{
public:
Dog(std::string petname);
~Dog();
};
Dog::Dog(std::string petname): Pet(petname)
{
}
Dog::~Dog()
{
std::cout << "死掉了一只" << Pet::petname<< std::endl;
}
//'''''''''Dog 狗
//'''''''''cat 猫
class Cat :public Pet
{
public:
Cat(std::string petname);
~Cat();
};
Cat::Cat(std::string petname) : Pet(petname)
{
}
Cat::~Cat ()
{
std::cout << "死掉了一只" << Pet::petname << std::endl ;
}
int main(void)
{
Dog dog("狗");
return 0;
}
|
|