Hi All!

We want to overload the new operator in two different ways.

i.e.
1.void* operator new(unsigned int aSize,int aLine, char* aFile);
2.void* operator new(unsigned int aSize, TLeave, int aLine, char* aFile);

For 1st one I did following way: It works fine.

void* operator new(unsigned int aSize,int aLine, char* aFile);
void* operator new(unsigned int aSize,int aLine, char* aFile)
{
//allocates size bytes and returns a pointer to the allocated memory
void* memptr = malloc(aSize);
//fill memory with a constant byte, clears the memory
memset(memptr,0,aSize);
return memptr;
}

#define new ::new((int)__LINE__, (char*)__FILE__)
For 2 different new overloads, I did following way

void* operator new(unsigned int aSize,int aLine, char* aFile);
void* operator new(unsigned int aSize, TLeave aLeave,int aLine, char* aFile);

void* operator new(unsigned int aSize,int aLine, char* aFile)
{
//allocates size bytes and returns a pointer to the allocated memory
void* memptr = malloc(aSize);
//fill memory with a constant byte, clears the memory
memset(memptr,0,aSize);
return memptr;
}

void* operator new(unsigned int aSize, TLeave aLeave, int aLine, char* aFile)
{
void* memptr = malloc(aSize);
if(memptr == NULL)
User::Leave(KErrNoMemory);
memset(memptr,0,aSize);
return memptr;
}

#define new ::new((int)__LINE__, (char*)__FILE__) ,new(TLeave, (int)__LINE__, char*(__FILE__))
When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
I am not sure how I will use TLeave in my overloaded new. I have called User::Leave(KErrNoMemory);

Any pointers regarding this will be highly appreciated.

Thanks