calling matching delete operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux