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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:23:29+00:00 2026-05-31T00:23:29+00:00

Class B; B *b = new B(); // default constructor B *b1 = new

  • 0
Class B;
B *b  = new B();       // default constructor
B *b1 = new B(10);     // constructor which takes an argument B(int x)

However, if we want to write a custom version of new, the syntax is

Class B
{
  /*...*/
  static void* operator new(size_t size);
}

How is the statement new B() converted to a function call for
operator new(sizeof(B))?

And how does it keep track of which constructor to call i.e. how does it distinguish between new B() and new B(int x)?

Is new implemented as a macro in C++?

  • 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-31T00:23:30+00:00Added an answer on May 31, 2026 at 12:23 am

    Your question should be:

    How compiler distinguish between new B() and new
    B(10)
    , when the B::operator new syntax is same ?

    Well, new just allocates the memory and immediately after that the compiler inserts the call to the constructor. So it’s irrespective if you call new B, new B() or new B(10).

    Compiler interprets something like:

    B *b = static_cast<B*>(B::operator new(sizeof(B)))->B();
    B *b1 = static_cast<B*>(B::operator new(sizeof(B)))->B(10);
    

    In actual a constructor doesn’t return anything. But above pseudo code is just an analogical representation of internal stuff.

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

Sidebar

Related Questions

The below code in Java throws Null pointer exception. public class New{ int i;
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
Whenever I write a new class and add some internal fields, I use an
I'm working on a new class to wrap XML handling. I want my class
I'm experiencing a weird issue in which I need to have a default constructor
I have a struct which takes 3 named parameters in to the constructor... public
My problem is that I have a class, which should take a long int
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
Collections is a public class, then we can call its implicit default constructor. It
If I have a auto_ptr I can pass it for a reference?Like: auto_ptr<MyClass>Class(new MyClass);

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.