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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:25:16+00:00 2026-05-23T08:25:16+00:00

When object is created in the heap, it (new) does two things. 1: calls

  • 0

When object is created in the heap, it (new) does two things.

1: calls operator new

2: calls constructor to initialize the obejct.

I am trying to create array of objects, for example 4 objects , so it calls constructor and destructor 4 times that makes sense but it only calls one time operator new[] ?? why? Following is the code that i am trying to run.

#include <iostream>
using namespace std;
class test
{
    public:
       static void *operator new[] (size_t size)
       {
           cout<<"operaotor new called"<<endl;
           return ::operator new[](size);
       }

       test()
       {
          cout<<"constructor called"<<endl;
       }
       ~test()
       {
          cout<<"destructor called"<<endl;
       }
};

int main()
{

     test *k = new test[4];
     delete []k;
}
  • 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-23T08:25:16+00:00Added an answer on May 23, 2026 at 8:25 am

    operator new[] is only there to allocate the necessary space, nothing else. Of course, it will do so only once, as anything else would be nonsens and wouldn’t get a contiguous buffer. The size parameter you’re getting, in the case of new test[4], should be 4 * sizeof(test).

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

Sidebar

Related Questions

In Visual C++, if I use new to create an object on the heap,
Whenever any new object is created, the object is created on heap. The memory
the following code (from a database object created for each new view): -(void)update:(NSString *)queryText{
Once a controller object is created when does it become available for garbage collection?
because obj, the playingCard object is created inside a nested for loop does that
I have a class whose object must be created on the heap. Is there
I need some clarification regarding runtime/heap issues when deleting an object which was created
In C++, is it possible to create an object on the heap without using
I'am wondering if built-in types in objects created on heap with new will be
I have tree control object created using CTreeCtrl MFC class. The tree control needs

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.