-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHowMany.cpp
More file actions
47 lines (38 loc) · 937 Bytes
/
HowMany.cpp
File metadata and controls
47 lines (38 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*************************************************************************
> File Name: HowMany.cpp
> Author: mushipu
> Mail: mushipu1988@163.com
> Created Time: Fri Mar 13 12:19:09 2015
************************************************************************/
#include <fstream>
using namespace std;
ofstream out("howmany.out");
class HowManyObjs {
static int object_count;
int obj;
public:
HowManyObjs() {
object_count++;
}
static void print(const char* msg = 0) {
if(msg) out << msg << ":";
out << "object_count = "
<< object_count << endl;
}
~HowManyObjs() {
object_count--;
print("~howmany()");
}
};
int HowManyObjs::object_count = 0;
// Pass and return BY value:
HowManyObjs f(HowManyObjs x) {
x.print("x argument inside f()");
return x;
}
main(){
HowManyObjs h;
HowManyObjs::print("after construction of h");
HowManyObjs h2 = f(h);
HowManyObjs::print("after call to f()");
}