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.
For 2 different new overloads, I did following wayvoid* 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__)
When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..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__))
I am not sure how I will use TLeave in my overloaded new. I have called User::Leave(KErrNoMemory);CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
Any pointers regarding this will be highly appreciated.
Thanks

Reply With Quote




