您的位置:首页 > 移动开发 > Objective-C

object构造、拷贝构造、析构、临时对象

2012-11-22 18:23 363 查看
 

#include <iostream>
using namespace std;

class howmany
{
static int count;

public:
howmany()
{
count++;
}

static void print(const char *msg = 0)
{
if (msg) cout << msg << ": ";
cout << "count = " << count << endl;
}

~howmany()
{
count--;
cout <<  "~howmany: " << count << endl;
}

};

int howmany::count = 0;
howmany f(howmany x)
{
x.print("x arg inside f()");
return x;
}

int main()
{
howmany h;

howmany::print("after h");
howmany h2 = f(h);
howmany::print("after call f()");
}

 

输出:

after h: count = 1

x arg inside f(): count = 1

~howmany: 0

after call f(): count = 0

~howmany: -1

~howmany: -2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: