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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:52:37+00:00 2026-05-13T17:52:37+00:00

I found this one question asking the same thing , however only the ‘new’

  • 0

I found this one question asking the same thing, however only the ‘new’ part was answered, so here goes again.

Why is the delete operator required to be static? Somehow it doesn’t make sense. The new operator makes perfect sense, just like the constructor can’t be virtual, neither can the new operator. However, the destructor can (and should) be virtual when you use inheritance, in order to allow destruction of objects being used (by way of polymorphism) as a base class.

I understand that, when the delete operator is called, the object has already been destroyed, so no ‘this’ exists. Yet it still makes sense, using the same reasoning as with virtual destructor, to have the delete operator match the new operator which created the object.

This is what I mean

class A
{
  public:
    virtual ~A() {}
};

class B : public A
{
  public:
    void* operator new (size_t sz);
    void  operator delete (void* ptr, size_t sz);
};

now if we do

A *ptr = new B();
delete ptr; // <-- fail

A’s delete operator (default) should’ve been called, since it’s static and it’s not known (for anything but the trivial case here) at compile time which delete-operator is the correct one.

However, I made a small test program with the code above (just malloc/free in the new/delete operators, and print statement in delete), and compiled it using g++. Running it quite unexpectedly produced the output in B’s delete operator.

My (real) question is this: Is there some implicit ‘virtualness’ to the delete operator? Is it only static in the no-this-pointer sense? Or is this just a g++ feature?

I started looking through the C++ specification, but I must admit, I was bit overwhelmed by it, so any help appreciated.

  • 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-13T17:52:38+00:00Added an answer on May 13, 2026 at 5:52 pm

    The answer in the language rules is really in 12.5 [class.free].

    If you are deleting via a pointer to a base class then the destructor must be virtual or you get undefined behaviour. Otherwise, the implementation has to determine the dynamic type of the object being deleted.

    12.5/4 says that when the delete isn’t prefixed by :: then the deallocation function is determined by looking up delete in the context of the dynamic type’s virtual destructor. This ensures virtual-like lookup, even though operator delete is always a static member function.

    Raw allocation and deallocation happen conceptually outside of the object’s lifetime so by the time the deallocation function is to be called, there is no longer an object to provide a virtual lookup mechanism but the lookup rules ensure that operator delete has a dynamic (virtual-lite!) lookup mechanism. This means that operator delete can sensibly be static without losing touch with the original object’s dynamic type.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could issue the BACKUP commands from ASP.NET the same… May 14, 2026 at 5:24 am
  • Editorial Team
    Editorial Team added an answer You will be better off using something like execute [1]… May 14, 2026 at 5:24 am
  • Editorial Team
    Editorial Team added an answer You can use the debugging console. This will show you… May 14, 2026 at 5:24 am

Related Questions

When adding code to an onclick handler, are there any limitations to what can
I'm working on a car dealer website at the moment, and I've been working
Before I begin: I have spent a long time on many forums (including Stack
I have a model Task which will HABTM many TaskTargets. When it comes to
I'm the guy who was here a while back asking about controlling Windows Media

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.