?? staticmember.cpp
字號:
//Listing 20.1 static data members
#include <iostream>
class Cat
{
public:
Cat(int age = 1):itsAge(age){HowManyCats++; }
virtual ~Cat() { HowManyCats--; }
virtual int GetAge() { return itsAge; }
virtual void SetAge(int age) { itsAge = age; }
static int HowManyCats;
private:
int itsAge;
};
int Cat::HowManyCats = 0;
int main()
{
const int MaxCats = 5;
Cat *CatHouse[MaxCats];
int i;
for (i = 0; i<MaxCats; i++)
CatHouse[i] = new Cat(i);
for (i = 0; i<MaxCats; i++)
{
std::cout << "There are ";
std::cout << Cat::HowManyCats;
std::cout << " cats left!\n";
std::cout << "Deleting the one which is ";
std::cout << CatHouse[i]->GetAge();
std::cout << " years old\n";
delete CatHouse[i];
CatHouse[i] = 0;
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -