我发现了一个小型的标准头文件<new>
。可能之前我没有直接使用过它。以下是我感兴趣的部分:这里是g++版本,供有兴趣的人参考。
struct nothrow_t { };
extern const nothrow_t nothrow;
/** If you write your own error handler to be called by @c new, it must
* be of this type. */
typedef void (*new_handler)();
/// Takes a replacement handler as the argument, returns the previous handler.
new_handler set_new_handler(new_handler) throw();
- 程序员如何使用
struct nothrow_t
及其对象nothrow
?对象是否需要被声明为extern
? new_handler
在什么情况下会被使用?- 为什么所有的
operator new/delete
都要在extern C++
块中声明?