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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:05:08+00:00 2026-05-28T07:05:08+00:00

class X { public: X (int); // … }; We can place objects anywhere

  • 0
class X 
{
public:  
  X (int);  
  // ...
};

We can place objects anywhere by providing an allocator function with extra arguments and then supplying such extra arguments when using new:

void* operator new(size_t, void *p)       
{ 
    return p; 
} // explicit placement operator  

void* buf = reinterpret_cast<void*>(0xF00F); // significant address    
X*p2 = new(buf)X;  //construct an X at ‘buf;’ invokes: operator new(sizeof(X),buf)

What does it means? What is reinterpret_cast and what it is doing here?
explain broadly…..

  • 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-28T07:05:08+00:00Added an answer on May 28, 2026 at 7:05 am

    There are two ways you can call operator new. The first way I’m assuming you’re familiar with:

    X *p1 = new X;
    

    With this usage you’re telling the compiler to do two things:

    1. allocate enough space to store an instance of X. This is done by calling the default allocator supplied by the standard runtime unless you globally overloaded operator new to do something different.
    2. fill out X’s data members and get it to a known initial state by calling one of X’s constructors.

    Now the second form of operator new presented in your code:

    X*p2 = new(buf) X;
    

    With this usage you’re basically telling the compiler do not allocate space for X. Instead use the space provided by buf to construct this instance of X. Step 2 is still performed but step 1 is skipped.

    The reinterpret_cast<void *> here is essentially telling the compiler whatever is at address 0xF00F, treat it as some generic data — no type or size is associated with this data. This is equivalent to doing a raw C-style cast:

    void* buf = (void*)0xF00F;
    

    This is done to satisfy operator new’s function signature:

    void* operator new(size_t, void *p)
    

    Note the generic pointer void *p — that will take on buf’s value passed in earlier. The cast is there to make their ‘types’ match. Also note that 0xF00F technically isn’t a valid address but we’ll pretend it is for this example.

    And that is what the code above is doing, explained broadly.

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

Sidebar

Related Questions

I have my objects like this. public class BaseTable { public int ID {
Given the following class public class Foo { public int FooId { get; set;
Consider the following class public class Class1 { public int A { get; set;
Say I have this class: public class Account { public int AccountID { get;
I have the following class: public class Account { public int AccountID { get;
I have the following class: public class Day { public int Date { get;
class Foo { public int A { get; set; } } class Program {
public class MyClass { public int Age; public int ID; } public void MyMethod()
public class JsonCategoriesDisplay { public JsonCategoriesDisplay() { } public int CategoryID { set; get;
Assuming public class MyClass { public int ID {get; set; } public string Name

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.