🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Goetz von Escher Fri, 11 Sep 1992 15:03
overloading delete operator in a base class
#1
Author: Goetz von Escher
Date: Fri, 11 Sep 1992 15:03
73 lines
2824 bytes
Hi folks!

I'm facing a simple problem. Maybe YOU can help:

----------------------------------------------------------------
MAIN PROBLEM:
----------------------------------------------------------------
I want to keep track of the size of memory used by objects of
specific classes (they are all derived from a common base
class). So I override the new and delete operators of the
base class and let a global integer count the number of
bytes used.

To implement this I have to know the size of an object when it
is deleted.

----------------------------------------------------------------
GNU PROBLEM:
----------------------------------------------------------------
I want to overload the delete operator inside a class, using the
two argument style (as expained in "The Annotated C++ reference
manual" by Ellis/Stroustrup in section 12.5) as:

   void operator delete(void*, size_t);

Unfortunately g++ (version 2.2.2) does not accept this, as
you can see when you try to compile the following code. If I
remove the two occurrences of size_t the program works well.

Is this a gnu bug/feature or am I missing something here?

----------------------------------------------------------------
TRY TO COMPILE THIS PROGRAM:
----------------------------------------------------------------
extern "C" {
#include <stdlib.h>
}
#include <iostream.h>

class Simple {
   public:
      Simple()  { cout << "constructor\n"; };
      ~Simple() { cout << "destructor\n"; };

      void operator delete (void*, size_t);
};

void Simple::operator delete (void* o, size_t s) {
   cout << "delete\n";
   ::delete(o);
}

int main() {
   Simple* s = new Simple();
   delete s;
   return 0;
}
----------------------------------------------------------------
ERROR MESSAGE PRODUCED ON MY COMPUTER (SUN SPARC):
----------------------------------------------------------------
[c++]% g++ overloading.delete.cxx
overloading.delete.cxx: In method `Simple::~Simple ()':
overloading.delete.cxx:9: too few arguments for method `operator delete'


Thanks for any suggestions...

----------------------------------------------------------------
Goetz von Escher             PHONE (613) 763-8681
14 Viewmount Dr              EMAIL crlstu4@bnr.ca
Nepean, Ontario K2G 1R5
CANADA
----------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads