Topic: Inheriting new and delete
Author: djones@megatest.com (Dave Jones)
Date: Wed, 16 Mar 1994 00:52:42 GMT Raw View
I somehow got the impression that the new proposed standard had it that
operators new and delete would no longer be inherited. Am I just imagining
things?
The new Sun C++ compiler does inherit them. The following writes out
"new new" and "new delete". Is that (still) what it is supposed to do?
#include <iostream.h>
#include <new.h>
template <class MemStore>
class Foo {
public:
void *operator new(size_t size) {
cerr << "new new" << endl;
return new char[size];
}
void operator delete(void *ptr) {
cerr << "new delete" << endl;
delete[] (char*) ptr;
}
};
class Bar: public Foo<tMem> {;};
int main(){
Bar *ptr = new Bar;
delete ptr;
return 0;
}