×

Discussion Board

Results 1 to 4 of 4

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Apr 2006
    Location
    India
    Posts
    383

    Exclamation Overloading new opearator

    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
    Regards,
    Shilpa Kulkarni

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Overloading new opearator

    Can you paste the Error Produced By the Compiler.

  3. #3
    Regular Contributor
    Join Date
    Apr 2006
    Location
    India
    Posts
    383

    Re: Overloading new opearator

    When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..
    Regards,
    Shilpa Kulkarni

  4. #4
    Regular Contributor
    Join Date
    Sep 2007
    Posts
    247

    Re: Overloading new opearator

    Quote Originally Posted by Shilpa13 View Post
    When I use it in my cpp files, with new(ELeave), it gives declaration syntax error at the following line..
    I am facing the same issue. Please let me know if your problem solved and the solution for the same.

Similar Threads

  1. Overloading of addCommand()
    By namrata in forum Mobile Java General
    Replies: 8
    Last Post: 2007-02-21, 12:29
  2. Overloading CEikDocument::OpenFileL() on Embedded Apps
    By ayulo in forum Symbian User Interface
    Replies: 3
    Last Post: 2004-03-25, 08:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×