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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:30:52+00:00 2026-05-16T05:30:52+00:00

I saw an example of using the function: delete in cpp and I didn’t

  • 0

I saw an example of using the function: delete in cpp and I didn’t completely understand it.
the code is:

class Name {
    const char* s;
    //...
};

class Table {
      Name* p;
      size_t sz;
public:
      Table(size_t s = 15){p = new Name[sz = s]; }
      ~Table { delete[] p; }
};

What is the exact action of the command: delete[] p;?

I think the aim was to delete all the pointers in the container Table.

The brackets in delete[] give me a clue that it deletes an array of pointers to Name but the size of the array is not specified, so how does the destructor “know” how many pointers to delete?

  • 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-16T05:30:52+00:00Added an answer on May 16, 2026 at 5:30 am

    delete isn’t a function, it’s an operator.

    A delete expression using [] destroys objects created with new ... [] and releases the associated memory. delete[] must be used for pointers returned by new ... []; non-array delete only on pointers returned by non-array new. Using the non-matching delete form is always incorrect.

    The delete expression in ~Table() (missing () in your code) will destroy the dynamically created array of Name objects ensuring that the Name destructor is called for each member of the array.

    It is up the the implementation to implement some mechanism of recording the number of elements in arrays allocated with new ... [] the programmer doesn’t have to worry about this.

    In many implementations, where the array elements have non-trivial destructors, a new[] expression will allocate extra space to record the element count before the space for all the array members. This hidden count is then looked up when delete[] is used to ensure the correct number of destructors are called. This is just an implementation detail, though, other implementations are possible.

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

Sidebar

Related Questions

I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
i saw a example for login form same blow code class Form_Login extends Zend_Form
I saw this as an example on MDN and didn't understand why this was
Here's an example I saw for some GLX code: display = XOpenDisplay(0); // ...
I saw very interesting example of using html5 css3 and javascript that is amazing,
I have made simple example of using canvas and then I saw that my
I saw an example today of a method overriding a method in a base
I recently saw an example of Google maps in grey on a website (Can't
Once, I saw an example like this: var a, x, y; var r =
I saw a Java example that had a main method labeled as synchronized, calling

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.