Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:05:54+00:00 2026-05-27T17:05:54+00:00

I have overloaded new and delete operators. I want to save pointers to ‘old’

  • 0

I have overloaded new and delete operators. I want to save pointers to ‘old’ new and delete to call it into ‘new’ new and delete. For example:

#include "h.h"
void * operator new ( size_t size, /*args*/ ) throw (std::bad_alloc)
{
    void * p = 0;
    p = original_new(size); //calling for 'old' new
    //some code
    return p;
}

And the similar operator delete.

So, I’m trying in my header file to type the following:

static void * (*original_new)(size_t) = ::operator new;
static void * (*original_new_arr)(size_t) = ::operator new[];
static void (*original_delete)(void *) = ::operator delete;
static void (*original_delete_arr)(void *) = ::operator delete[];

It is successfully compiled, but I have core dump on start.
It is possible to call malloc in new bad it is really bad idea. It is possible to call new(std::nothrow) but it is bad too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:05:55+00:00Added an answer on May 27, 2026 at 5:05 pm

    You don’t need to save pointers; defining a placement new operator (any
    operator new function which takes more than one argument) doesn’t
    remove the existing operators; it just overloads them. To call the
    standard operator new function from a placement operator new function:

    p = ::operator new( size );
    

    Note that you do not want to do this if your placement new returns
    anything but the exact address returned by ::operator new. Otherwise,
    delete won’t work. If you use any placement new that return anything
    other than a pointer returned by ::operator new, you need to define a
    new global operator delete (because this is the one that will be
    called), which in turn means that you have to define a new standard
    operator new as well, so that it will work correctly with your new
    operator delete. In order to avoid having to implement all of the
    memory management yourself, use malloc and free in your
    implementations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with VC++ 2005 I have overloaded the new and delete operators.
In one project I have globally overloaded operator new/delete to make use of a
I want to use the new and delete operators for creating and destroying my
I have an overloaded function which I want to pass along wrapped in a
If I have have some overloaded ostream operators, defined for library local objects, is
I have the template class and array of pointers to objects and overloaded logic
Returning a new object on overloaded operators seems the only thing to do. Right?
I have a class on which I am overloading new and delete (these fetch
I have a dylib written in C++ which has an overloaded operator new and
Have you overloaded operator new in C++? If yes, why? An interview question, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.