📄 ex3-2-1g.cpp
字号:
//From Thinking in C++ Vol 2, Bruce Eckel
//: C11:HowMany.cpp
// A class that counts its objects
#include <iostream>
using namespace std;
class HowMany
{
private:
static int objectCount;
public:
HowMany() { objectCount++; }
HowMany(HowMany& h) { objectCount++; }
static void print(const char * msg = NULL)
{
if(msg) cout << msg << ": ";
cout << "objectCount = " << objectCount << endl;
}
~HowMany()
{
objectCount--;
print("~HowMany()");
}
};
int HowMany::objectCount = 0;
// Pass and return BY VALUE:
HowMany f(HowMany x)
{
x.print("x argument inside f()");
return x;
}
void main()
{
HowMany h;
HowMany::print("after construction of h");
HowMany h2 = f(h);
HowMany::print("after call to f()");
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -