I have overloaded the new operator for a type X
to use some memory pool. My new
operator takes no user-defined arguments, thus, the only argument is the size of the object of type size_t
. At another part of the program, I need placement new for the same type, like this:
new (ptr) X();
(where ptr is a pointer to a preallocated memory location)
It seems that my overload of the new operator for the type shadows placement new. At least, the compiler complains:
error: no matching function for call to ‘X::operator new(long unsigned int, X*&)’
note: candidate is:
note: static void* X::operator new(size_t)
note: candidate expects 1 argument, 2 provided
The candidate is my overload of the new operator. My questions are:
- Why doesn't the compiler recognize that I want to use placement new?
- How can I use it anyway?
- WTF is the type
X*&
shown in the error message?