This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

calling matching delete operator


Hello

I am trying to overload the 'new' and 'delete' operators in C++. But
unfortunately it seems that the corresponding delete operator is not
called for my overloaded new.


Here is the code that gives me trouble:
///////////////////////////////////////////////////////////////
#include <iostream>

void * operator new(size_t size,const char *desc)
{
  std::cout << "Custom new call: " << desc << std::endl;
  return malloc(size);
}

void operator delete(void *p,const char *desc)
{
  std::cout << "Custom delete called: " << std::endl;
  free(p);
}

void operator delete(void *p)
{
  std::cout << "Overloaded delete called, but no parameter match" <<
std::endl;
  free(p);
}

class A
{
};

int main(int argc,char *argv[])
{
  A *a = new("Allocing class A") A();
  delete a;
  return 0;
}
///////////////////////////////////////////////////////////////

For this code I would expect following output:

"Custom new call: Allocing class A
Custom delete called :"

but I get this output:
"Custom new call: Allocing class A
Overloaded delete called, but no parameter match"

Am I doing something wrong ?
Could somebody please help me out.

Thanks.

Regards,
Gerald



	

	
		
___________________________________________________________ 
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]