Carousel Carousel - 2 months ago 6x
C++ Question

Is `operator new` a part of C++ core language?

I have been told that "new-expression will call

operator new
to manage dynamic storage and initialize the object at the same time" many times. And I don't doubt about that. But I'm wondering that since
operator new
is declared in standard library header
, how could we still using new-expression even if we include no header files.

operator new
a part of C++ core language or the compiler includes


Yes operator new is part of the standard. The implementation is required to supply the operator at the global scope in each translation unit in your program. From []/2

The library provides default definitions for the global allocation and deallocation functions. Some global allocation and deallocation functions are replaceable (18.6.1). A C++ program shall provide at most one definition of a replaceable allocation or deallocation function. Any such function definition replaces the default version provided in the library ( The following allocation and deallocation functions (18.6) are implicitly declared in global scope in each translation unit of a program.

void* operator new(std::size_t);
void* operator new[](std::size_t);
void operator delete(void*);
void operator delete[](void*);
void operator delete(void*, std::size_t) noexcept;
void operator delete[](void*, std::size_t) noexcept;

emphasis mine

This is why you do not need to include anything to use new/new[] and delete/delete[].