-
class obj
-
{
-
private :
-
char ch;
-
public:
-
obj(char c);
-
~obj();
-
};
-
#include "iostream"
-
using namespace std;
-
-
void f();
-
obj A('A');
-
-
int main()
-
{
-
cout<<"inside main()"<<endl;
-
f();
-
f();
-
cout<<"outside main()"<<endl;
-
//printf("outside main()");
-
return 0;
-
}
-
obj::obj(char c):ch(c)
-
{
-
cout<<"construct ........."<<ch<<endl;
-
}
-
obj::~obj()
-
{
-
-
printf("destruct...........");
-
printf("%c\n",ch);
-
//cout<<"destruct..........."<<ch<<endl;
-
}
-
void f()
-
{
-
static obj B('B');
-
obj C('c');
-
-
}
运行结果:
如果析构函数中采用cout进行打印,会出现:析构函数没有被自动调用的现象。
参考文章:
阅读(1152) | 评论(0) | 转发(0) |