R
Rahul
Please read the following code
class Test{
public:
void * operator new [] (size_t t)
{ return malloc(t); }
void operator delete [] (void *p)
{ free(p); }
};
void main () {
Test *p= 0;
delete [] p;
/* What should happen here, Should the call go inside Test:perator
delete []. Because what I learned from books is that deleting a NULL
pointer is safe (calling :perator delete[] on a NULL pointer does
not crash). But here it causes a crash on Sun CC because it gets
inside Test:perator delete [] whereas on VC++ and g++ it doesn't.
Should I put a check in Test:perator delete [] for "p!
=NULL"? Is Sun CC behaving as per the C++ standard?
*/
}
Thanks in advance
class Test{
public:
void * operator new [] (size_t t)
{ return malloc(t); }
void operator delete [] (void *p)
{ free(p); }
};
void main () {
Test *p= 0;
delete [] p;
/* What should happen here, Should the call go inside Test:perator
delete []. Because what I learned from books is that deleting a NULL
pointer is safe (calling :perator delete[] on a NULL pointer does
not crash). But here it causes a crash on Sun CC because it gets
inside Test:perator delete [] whereas on VC++ and g++ it doesn't.
Should I put a check in Test:perator delete [] for "p!
=NULL"? Is Sun CC behaving as per the C++ standard?
*/
}
Thanks in advance