65,187
社区成员




#include <iostream>
#include <string>
using namespace std;
class HowMany2{
static int objectCount;
public:
HowMany2(const string& id)
{
++objectCount;
print("HowMany2()");
}
/*
~HowMany2()
{
--objectCount;
print("~HowMany2()");
}
*/
HowMany2(const HowMany2& h)
{
++objectCount;
print("HowMany2(const HowMany2&)");
}
void print(const string& msg = "") const
{
if(msg.size() != 0)
cout<<msg<<endl;
cout<<"\t"<<"对象数量: "<<"objectCount = "<<objectCount<<endl;
cout<<endl;
}
};
int HowMany2::objectCount = 0;
HowMany2 f(HowMany2 x)
{
cout<<"Entering f()\n";
return x;
}
void main()
{
HowMany2 h("h");
HowMany2 h2 = f(h);
}