c++问题 静态属性与静态方法 编译不通过求解
#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 :publicPet
{
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;
}
Pet里的静态变量count没有初始化 解决了吗 用一下代码格式+注释会更美观哦!
页:
[1]