ex3-2-1.cpp
来自「一些学习c++的例题」· C++ 代码 · 共 44 行
CPP
44 行
//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++; }
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 + =
减小字号Ctrl + -
显示快捷键?