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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:20:03+00:00 2026-06-10T01:20:03+00:00

I am trying to implement operator new with parameter as global. There is no

  • 0

I am trying to implement operator new with parameter as global. There is no problem if new without args is overloaded, but I get followings errors when trying to compile

inline void* operator new(size_t, void* p) {
    //...
    return p;
}

c:\bjarne_exercise_6.cpp(14): error C2084: function ‘void *operator new(size_t,void *) throw()’ already has a body
c:\program files\microsoft visual studio 10.0\vc\include\new(55) : see previous definition of ‘new’

c:\bjarne_exercise_6.cpp(40): error C2264: ‘operator new’ : error in function definition or declaration; function not called

I have just solved this, you have to declare this before you #include stdafx.h
No, not true. It compile well but still not this function is called but the version from new header file. It is so, because placement new(with 2 params) is already defined in new header. The ordinary new (with just 1, size_t parameter) is only declared there, so you can still overload it. So if you want special new with more than 1 parameter the solution suggested by @trion below is appropriate.

  • 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-06-10T01:20:05+00:00Added an answer on June 10, 2026 at 1:20 am

    The C++ standard defines a placement operator new taking an additional void* in the header file <new>.
    Its implementation is similar to this:

    void* operator new(size_t, void* m)
    {
        return m;
    }
    

    It’s commonly used to instantiate objects on already allocated memory, e.g. by STL containers which separate allocation from instantiation. So if you include any standard header depending on <new>, the placement new will already be defined.

    If you want to create your own version of operator new with different semantics, you can use a dummy parameter to disambiguate the situation:

    struct my_new_dummy {} dummy;
    void* operator new(size_t, my_new_dummy, void* m);
    
    //...
    
    int mem;
    int* ptr = new(dummy, &mem) int;
    

    Edit: The reason why you can redefine the ordinary operator new but not placement new, is that the former is by default defined by the compiler and can be overridden manually, whereas placement new is defined in a header, therefore causing a conflict with your re-definition.

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

Sidebar

Related Questions

Trying to implement google C2DM service. registrationIntent.putExtra(app, PendingIntent.getBroadcast(context,0,new Intent(), 0)); registrationIntent.putExtra(sender,example@gmail.com); context.startService(registrationIntent); Almost every
I am trying to implement admin login and operators(india, australia, america) login, now operator
I'm trying to implement the command design pattern , but I'm stumbling accross a
I am trying to implement the Like operator by using the entity framework query.
I am very new to C++ and I am trying to implement a TriangleDynamic
I am trying to implement a fixed-point class in C++, but I face problems
I'm trying to implement cycling iterator, which is quite useful in my problem. According
After coming up against this problem myself in trying to implement a generic Vector2<int/float/double>
I'm new to C++ and trying to implement a turtle emulator that will read
I am new to boost. I am trying to implement boost::unorder_set. Here is the

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.