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

  • Home
  • SEARCH
  • 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 7018441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:03:05+00:00 2026-05-27T23:03:05+00:00

I know you can overload the operator new . When you do, you method

  • 0

I know you can overload the operator new. When you do, you method gets sent a size_t parameter by default. However, is it possible to send the size_t parameter – as well as additional user-provided parameters, to the overloaded new operator method?

For example

int a = 5;
Monkey* monk = new Monkey(a);

Because I want to override new operator like this

void* Monkey::operator new(size_t size, int a)
{

...

}

Thanks

EDIT: Here’s what I a want to accomplish:

I have a chunk of virtual memory allocated at the start of the app (a memory pool). All objects that inherit my base class will inherit its overloaded new operator.
The reason I want to sometimes pass an argument in overloaded new is to tell my memory manager if I want to use the memory pool, or if I want to allocate it with malloc.

  • 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-27T23:03:06+00:00Added an answer on May 27, 2026 at 11:03 pm

    Invoke new with that additional operand, e.g.

     Monkey *amonkey = new (1275) Monkey(a);
    

    addenda

    A practical example of passing argument[s] to your new operator is given by Boehm’s garbage collector, which enables you to code

     Monkey *acollectedmonkey = new(UseGc) Monkey(a);
    

    and then you don’t have to bother about delete-ing acollectedmonkey (assuming its destructor don’t do weird things; see this answer). These are the rare situations where you want to pass an explicit Allocator argument to template collections like std::vector or std::map.

    When using memory pools, you often want to have some MemoryPool class, and pass instances (or pointers to them) of that class to your new and your delete operations. For readability reasons, I won’t recommend referencing memory pools by some obscure integer number.

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

Sidebar

Related Questions

I know that we can't overload operator with other meaning, we can't create new
I know you can overload an existing operator. I want to know if it
Is it possible to overload the new operator so that an object isn't created,
We all know that you can overload a function according to the parameters: int
You can know if the event stack is empty calling the gtk.events_pending() method, but
Possible Duplicate: How do I overload the square-bracket operator in C#? Basically I want
I know it's not possible to overload operators in as3, and have been using
I can't seem to find the way to overload the [] operator in javascript.
I know the = operator can't be overloaded, but there must be a way
I am trying to write operator overload for custom class and don't know how

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.