schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (10/07/88)
Hi,
I recently discovered the joy of overloading keyword new in G++.
However, is it possible to overload delete as well? Here's the example:
----------------------------------------
#include <stream.h>
const int Max_Buf = 10;
class foo {
private:
int j;
int k;
static int *Head, *Ptr;
public:
foo(int i) {
j = k = i;
}
int Return(void) {
return(j * k);
}
void * operator new(long Size) {
if (!Head) {
Ptr = Head = (int *) malloc(Size * Max_Buf);
}
void *Temp = Ptr--;
if (Ptr <= Head) {
Head = 0;
}
cout << "Temp = " << int(Temp) << "\n";
return(Temp);
}
void operator delete(long size) {
cout << "Hello\n";
}
};
main() {
foo Bar ( 1 );
cout << "Bar.Return() = " << Bar.Return() << "\n";
for ( int i = 0; i < 20; i++ ) {
foo *Bard = new foo(i);
cout << "&Bard = " << int(Bard) << "\n";
delete Bard;
}
}
----------------------------------------
This doesn't appear to call delete in version 1.27. Am I using
the correct syntax and semantics?
thanks,
Doug