马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
class Dog
{
public:
Dog();
~Dog();
static int getcount();
private:
static int count;
};
int Dog::count = 0;
Dog::Dog()
{
count += 1;
std::cout << "add" << '\n';
}
Dog::~Dog()
{
count -= 1;
std::cout << "subtract" << '\n';
}
int Dog::getcount()
{
return count;
}
int main()
{
std::cout <<"count =" << Dog::getcount() << '\n';
Dog dog1; Dog dog2;
std::cout << "count = " << Dog::getcount() << '\n';
{
Dog dog3;
std::cout << "count = " << Dog::getcount() << '\n';
}
std::cout << "count = " << Dog::getcount() << '\n';
return 0;
}
|