When is #include library required in C++?

后端 未结 4 2048
逝去的感伤
逝去的感伤 2020-12-01 05:19

According to this reference for operator new:

Global dynamic storage operator functions are special in the standard library:

  • Al
4条回答
  •  青春惊慌失措
    2020-12-01 05:35

    Operator new defined in header throws bad_alloc exception (which is declared in the same header) instead of returning NULL when memory allocation is not possible. header also defines

    void* operator new (std::size_t size, const std::nothrow_t& nothrow_constant) throw();
    

    variant which does not throw exceptions and placement new variant. Without you get only plain old, NULL-returning operator new. All three operator overloads:

    void* operator new (std::size_t size) throw (std::bad_alloc);
    void* operator new (std::size_t size, const std::nothrow_t& nothrow_constant) throw();
    void* operator new (std::size_t size, void* ptr) throw();
    

    are declared in header. However, some compilers may make them available implicitly, but this is non-standard, and you should not rely on it.

提交回复
热议问题