Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding New and Delete Operators

Status
Not open for further replies.

Dannybe2

Programmer
Jan 31, 2001
136
0
0
GB
Hi,

I am having a problem overriding the new and delete operators. I have overwritten the new operator with the following:

Code:
void * operator new(size_t size, char const* file, int line)
{
	void* v = malloc(size + sizeof(size_t));
	return v;
}

and the delete with the following:

Code:
void operator delete(void * del, char const* file, int line)
{
	free(del);
}

However I am getting an error message saying that no matching operator delete is found to match the new above.

Why does my program not recognise that the delete I have used is to match the new? Do I have to add anything to it to make it explicit?

Thanks,
Dan
 
shouldnt that be :-

static void* operator new(size_t size, char const* file, int line)

and

static void operator delete(void* memaddr,size_t size,char const* file,int line)

Also in his book effective c++ I believe scott meyers suggests checking the size of the object passed to your operator delete is the expected size or else pass it on to global delete. See item 10 effective c++
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top