2

I read other posts (one example: How could I sensibly overload placement operator new?) that C++ standard disallows overloading the global placement new.

GCC did throw an error when I defined:

void* operator new(size_t sz, void*) {
    std::cout << __PRETTY_FUNCTION__ << std::endl;
}

However, GCC allows me to define:

template <class T>
void* operator new(size_t sz, T t) {
    std::cout << __PRETTY_FUNCTION__ << std::endl;
}

I tried to use placement new and the function template above did get call.

How does it differ from replacing placement new? What's the rationale that C++ standard forbids overloading global placement new?

Community
  • 1
  • 1
Hei
  • 1,844
  • 3
  • 21
  • 35

0 Answers0