?????????????C++??????????
???????????? ???????[ 2013/3/19 10:28:35 ] ????????
????????f()??????
????*********************************************************
???????<<Thinking in C++>>?е???δ????????????????????????????????
//: HowMany_2.cpp
#include <string>
#include <iostream>
using namespace std;
class HowMany {
string name;
static int objectCount;
public:
HowMany(const string& id = "") {
name = id;
++objectCount;
print("HowMany()");
}
~HowMany() {
--objectCount;
print("~HowMany()");
}
HowMany(const HowMany& h) {
name = h.name + "copy";
++objectCount;
print("HowMany(const HowMany&)");
}
void print(const string& msg = "") {
if (msg.length() != 0) {
cout << msg << endl;
}
cout << ' ' << name << ": "
<< "objectCount = " << objectCount << endl;
return ;
}
};
int HowMany::objectCount = 0;
HowMany f(HowMany x) {
x.print("x argument inside f()");
cout << "Return From f()" << endl;
return x;
}
int main() {
{
HowMany h("h");
cout << "Entering f()" << endl;
HowMany h2 = f(h);
cout << "Call f()?? no return value" << endl;
f(h);
cout << "After call to f()" << endl;
}
// getchar();
return 0;
} ///:~