Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!oberon!nunki.usc.edu!jeenglis From: jeenglis@nunki.usc.edu (Joe English) Newsgroups: comp.lang.c++ Subject: Free store overloading Message-ID: <3439@nunki.usc.edu> Date: 9 Apr 89 23:32:28 GMT Reply-To: jeenglis@nunki.usc.edu (Joe English) Organization: University of Southern California, Los Angeles, CA Lines: 78 Wouldn't it make sense to be able to overload operators new and delete for class objects than to have to assign to 'this' in the constructors and destructor? Also, if operator delete could be overloaded, it would obviate the need in the destructor to find out if the object was dynamically or statically allocated. The Book says that operators new and delete may be overloaded, but it doesn't say exactly how. I tried overload operator delete; overload operator new; void operator delete (myclass *); // this makes sense to me myclass * operator new (void /* what goes here??? */); but my compiler (Zortech 1.06) wouldn't take it. (It choked on the overload declarations, and complained about redefining _new and _delete when I removed them). I also tried class myclass { ... myclass *operator new(void /* again, what should go here? */); void operator delete(myclass *); ... }; which the compiler accepted, but apparently ignored entirely. I haven't tried either method on gcc yet. So, what's the story? Is it possible to do what I'm trying to do, and will it be possible in future definitions of C++? While I was experimenting with this, I found what seem to be bugs in Zortech C++ version 1.06. Those who don't use (and didn't write :-) Zortech can skip this part... The program in question was testing an implementation of class string. BLINK couldn't find _vec_delete(); I had to link vector.obj directly. (I've had this problem before, but I understand it's been fixed in 1.07). Examining the assembly code, I found that it never called _vec_new or otherwise initialized a 3-D array of strings. string::string(void) was declared and in scope. Constructors for which tried to overload the standard allocator by assigning to 'this' in the function body still compiled a call to _new() at the start of the function. (This ended up fixing the program though, since my allocator got called when _new failed...) The destructor behaved properly, although the optimizer didn't take out the call to _delete even though it was always skipped. That's no big deal; I was just surprised since it's usually much smarter. Are these known problems, and have they been fixed in 1.07 (which I'm going to buy any day now...)? Also, what is the official procedure for reporting bugs? (I know Walter reads this newsgroup, so I figured that here was as good as anywhere else...) I should mention that I'm very happy with Zortech C++; these are the first serious problems I've encountered. I've been using it for several months now and it's made my life *much* easier. Thanks, --Joe English jeenglis@nunki.usc.edu