[阅读: 414] 2007-03-05 04:15:11
#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/
