中国开发网: 论坛: 程序员情感CBD: 贴子 479571
王中王: 稍改了一下:
#include <stdio.h>
#include <memory>


class TOtherObject
{
public:
TOtherObject()
{
printf("TOtherObject()\n");
};
~TOtherObject()
{
printf("~TOtherObject()\n");
};
};

class TMyObject
{
private:
std::auto_ptr<TOtherObject> OtherObject;
public:
TMyObject()
{
printf("TMyObject()\n");
OtherObject = std::auto_ptr<TOtherObject>(new TOtherObject());
throw "TMyObject() Exception";
};
~TMyObject()
{
printf("~TMyObject()\n");
};
};

void main(void)
{
TMyObject * MyObject;
try
{
MyObject = new TMyObject();
delete MyObject;
}
catch(...)
{
printf("Catch Exception\n");
};
getchar();
};

输出:
TMyObject()
TOtherObject()
~TOtherObject()
Catch Exception

C++Builder6
http://wangzw.wordpress.com/
个性化台历、日历制作
http://shop33697570.taobao.com/

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录