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 94655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:32:08+00:00 2026-05-10T23:32:08+00:00

The problem I’m running into is that as far as I know the delete

  • 0

The problem I’m running into is that as far as I know the delete operator should be a static function but sometimes the compiler (VC++) seems to be treating it as dynamic.

Given:

class Base { public:   void* operator new(size_t size) { /* allocate from custom heap */ }   void operator delete(void *p) { customFree(p, sizeof(Base)); }    Base() {}   virtual ~Base() {} };  class Derived: public Base { public:   void* operator new(size_t size) { /* allocate from custom heap */ }   void operator delete(void *p) { customFree(p, sizeof(Derived)); }    Derived() {}   virtual ~Derived() {} } 

What I see happening is that deleting the base pointer will result in call to Derived::opeator delete.

Base *p = new Derived(); delete p; //calls Derived::operator delete 

If I don’t define ANY destructors then I get what I expected to happen: Base::operator delete is called. This seems to be happening because the compiler is inserting a function called ‘scalar deleting destructor into the vtable when a destructor is defined. Then that function will call Derived::delete.

So I have to questions: 1) Is this standard behavior? 2) When should I be using

void operator delete( void *, size_t ); 

vs.

void operator delete( void * ); 

if the above is standard behavior?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T23:32:09+00:00Added an answer on May 10, 2026 at 11:32 pm

    It is certainly Standard Behavior. If the derived class’s operator new was used, its operator delete will also be used (also note even though you do not explicitly tell the compiler those functions are static, they are implicitly declared so). There might be the naughty case where you have an operator new in the derived class, but the corresponding operator delete is in the base class. I think that’s valid, but i would avoid that. Relying on the base operator delete, while defining ones own operator new in the derived class will inevitable cause trouble.

    If I don’t define ANY destructors then I get what I expected to happen:

    You will get undefined behavior 🙂 Everything can happen, including something you would expect (wrongly). Deleting through a base pointer that points to an object of another type requires a virtual destructor. The implicitly declared destructor is not virtual.

    When should I be using void operator delete( void *, size_t );

    If you want to have the size that was allocated known in the operator delete. I wrote about what it means here: What does the C++ new operator do other than allocation and a ctor call? . If you use (from within your overloaded member operator delete/new) the global operator new & delete to get your memory and release it, or even malloc / free, you don’t need that size information. But it could be useful for logging purposes.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
I am currently running into a problem where an element is coming back from
Problem: I don't know why my script is not loading a value into the
Problem: Trying to create a Mix that is applied to the AVPlayerItem, but it
Problem summary: (i) Widget in static portion of form works fine; but (ii) In
Problem: Ajax suggest-search on [ n ] ingredients in recipes. That is: match recipes
Problem solved: Thanks guys, see my answer below. I have a website running in
Problem: We have a web app that calls some web services asynchronously (from the

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.