Consider the following code:
#include <cstdlib>
class Base
{
public:
virtual ~Base() noexcept = default;
void* operator new[](size_t count) { return std::malloc(count); }
void operator delete[](void* ptr) { std::free(ptr); }
};
class Derived : public Base
{
};
int main()
{
auto ptr = new Derived[100];
delete[] ptr;
}
Compiling this with a recent version of MSVC in an environment which does not have a C++ runtime implementation (such as with the /NODEFAULTLIB switch) throws an unresolved external error for the global operator delete[], even though a class version is available:
error LNK2019: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) referenced in function main
However, when compiled with the C++ runtime, the class version of the operator is called as expected.
What is going on here?