Overloading new opearator
Hi All!
We want to overload the new operator in two different ways.
i.e.
[B]1.[/B]void* operator new(unsigned int aSize,int aLine, char* aFile);
[B]2.[/B]void* operator new(unsigned int aSize, TLeave, int aLine, char* aFile);
For 1st one I did following way: It works fine.
[QUOTE]
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__)
[/QUOTE]
For 2 different new overloads, I did following way
[QUOTE]
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__))
[/QUOTE]
When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..
[QUOTE]
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
[/QUOTE]
[U]I am not sure how I will use TLeave in my overloaded new. I have called User::Leave(KErrNoMemory);[/U]
Any pointers regarding this will be highly appreciated.
Thanks
Re: Overloading new opearator
Can you paste the Error Produced By the Compiler.
Re: Overloading new opearator
When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..
Re: Overloading new opearator
[QUOTE=Shilpa13;289947]When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..[/QUOTE]
I am facing the same issue. Please let me know if your problem solved and the solution for the same.