Re: Is it *legal* (as opposed to sensible) to explicitly destruct
an object and deallocate the memory?
<snip -- sorry, hit the quoted lines limit>
On 12/12/2010 17:05, Leigh Johnston wrote:
The following might be a consideration:
struct foo
{
foo()
{
std::cout << "foo ctor called\n";
}
~foo()
{
std::cout << "foo dtor called\n";
}
void* operator new(std::size_t aSize)
{
std::cout << "overloaded operator new called\n";
return ::operator new(aSize);
}
void operator delete(void* p)
{
std::cout << "overloaded operator delete called\n";
return ::operator delete(p);
}
};
int main()
{
foo *x = new foo;
delete x;
//x->~foo();
//::operator delete(x);
foo *y = new foo;
//delete y;
y->~foo();
::operator delete(y);
return 0;
}
outputs:
overloaded operator new called
foo ctor called
foo dtor called
overloaded operator delete called
overloaded operator new called
foo ctor called
foo dtor called
/Leigh
That certainly seems to add one more reason why it's not a sensible
thing to do, at any rate :)
Cheers!
Stu