I want to define my own placement new and placement delete(taking extra parameters), and I found I could invoke the placement correctly, while I couldn't access the placement delete. Could anyone tell me whether I define the placement delete incorrectly or I invoke it incorrectly?
class A
{
public:
A( int a ) : a(a){}
static void* operator new( std::size_t, int ); // the placement new
static void operator delete( void*, int )throw(); // the corresponding placement delete
private:
int a;
};
void* A::operator new( std::size_t size, int n )
{
std::cout << "size: " << size << " " << "n: " << n << std::endl;
return ::operator new(size);
}
void A::operator delete( void* p, int n )throw()
{
std::cout << "n: " << n << std::endl;
::operator delete(p);
}
int main( int argc, char* argv[] )
{
A* a = new(10) A(100);
std::cout << std::endl;
delete(4) a; // error???????????????????, but how?
return 0;
}