我想定义我自己的放置新和放置删除(采用额外参数),我发现我可以正确调用放置,而我无法访问放置删除。谁能告诉我是我错误地定义了展示位置删除还是我错误地调用了它?
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;
}