gpt4 book ai didi

c++ - 静态成员回收内存并从异常中恢复

转载 作者:太空宇宙 更新时间:2023-11-04 12:15:37 24 4
gpt4 key购买 nike

<分区>

这是我的作业题

Create a class with its own operator new. This operator should allocate 5 objects, and on 5th 'run out of memory' and throw an exception. Also add a static member function that reclaims this memory. Now create a main () with try block and catch clause that calls the memory-restoration routine. Put these inside a while loop to demonstrate recovering from an exception and continuing execution.

现在我不要程序了,但是我对这个问题很困惑。我可以处理新的运算符重载,但按照要求我应该创建一个静态成员“release()”。如果我必须在捕获中恢复,我该如何恢复?我的意思是我应该删除什么对象。或者我的 release() 原型(prototype)是错误的?

编辑:
另外,如果我必须删除,我可以删除 5 个对象中的哪个?删除任何对象实际上都是不正确的。我看不到恢复的方法。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com