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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:48:59+00:00 2026-05-24T15:48:59+00:00

so I’m using the boost::serialization library, and I’m trying to overide how a class

  • 0

so I’m using the boost::serialization library, and I’m trying to overide how a class is constructed, since it has no default constructor. This is demonstrated here. To me it appears the function takes the class* t and then sets it to point to a newly constructed object. If i’m wrong, this is definately the source of my error.

However, the only way to construct my class is by using another classes create() function, meaning I need to stray from the code in the example (this is stated in the boost::serialization namespace): ::new(t)my_class(attribute);

I tried simply calling the create function and setting t equal to the returned pointer, but this doesn’t seem to work because right after the load_construct_data function, and in the serialization function, the given myClass& is not the same as what I set ‘t’ to.

How do I do whatever ::new(t) is doing so the object created using the create function follows through into the serialize/other functions?

  • 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-24T15:49:01+00:00Added an answer on May 24, 2026 at 3:49 pm

    The construct referred to in your question (new(t) my_class(attribute)) is called “placement new”. The way it work is that

    1. t must already point to an allocated region of memory (placement new doesn’t do allocation by default)
    2. An instance of my_class is constructed at that memory location.

    However, since in your case you can’t use constructors, then using any form of new is out of the question. But there is an alternative (sort of).

    Since placement new pretty much just overwrites a chunk memory, we can use a regular function which does the same with an already constructed object. Such a function is memcpy:

    void * memcpy ( void * destination, const void * source, size_t num );
    

    All memcpy does is perform a byte-wise copy of num bytes from the memory pointed to by source to the memory pointed to by destination.

    So let’s say you started with this code in the load_construct_data

    my_class obj = other_class::create();
    

    Then we can use the memcpy function to “move” the value at obj into the memory reference by t:

    memcpy((void*)t, (void*)(&obj), sizeof(obj));
    

    While there are some details about how this works with your particular class, such as whether a bit-wise copy is “good enough”, this is the best I’ve got with what you’ve asked. The one problem I see is if the destructor releases resources, than the copy will may become invalid.

    To account for the possible problems with destruction, you can write your own deep copying function:

    void deepCopy( my_class * destination, const my_class * source );
    

    which you call instead of memcpy.

    Note: please tell me if I went astray with anything here. I don’t currently have a machine to test code on.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Does anyone know how can I replace this 2 symbol below from the string
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What 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.