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
  • 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. 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

Ask A Question

Stats

  • Questions 245k
  • Answers 245k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Java 7 introduced Automatic Resource Block Management which brings this… May 13, 2026 at 8:20 am
  • Editorial Team
    Editorial Team added an answer Did you set the "inverse" attribute to "true" for the… May 13, 2026 at 8:20 am
  • Editorial Team
    Editorial Team added an answer You can run your application as an External Tool, and… May 13, 2026 at 8:20 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
The problem: I have a class which contains a template method execute which calls
The Problem I use a tool at work that lets me do queries and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.