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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:33:18+00:00 2026-05-28T02:33:18+00:00

Sometimes it’s nice to start over. In C++ I can employ this following simple

  • 0

Sometimes it’s nice to start over. In C++ I can employ this following simple manoeuvre:

{

    T x(31, Blue, false);

    x.~T();                        // enough with the old x

    ::new (&x) T(22, Brown, true); // in with the new!

    // ...
}

At the end of the scope, the destructor will run once again and all seems well. (Let’s also say T is a bit special and doesn’t like being assigned, let alone swapped.) But something tells me that it’s not always without risk to destroy everything and try again. Is there a possible catch with this approach?

  • 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-28T02:33:19+00:00Added an answer on May 28, 2026 at 2:33 am

    I think the only way to make this really safe to use is to require the called constructor to be noexcept, for example by adding a static_assert:

    static_assert(noexcept(T(22, Brown, true)), "The constructor must be noexcept for inplace reconstruction");
    T x(31, Blue, false);
    x.~T();
    ::new (&x) T(22, Brown, true);
    

    Of course this will only work for C++11.

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

Sidebar

Related Questions

Sometimes I heard people discussing about the start-up time for Java. It seems this
Sometimes I feel I can't write a simple line of code without using an
Sometimes i face the following problem : string txt = con.Request.Params[Par_name].ToString();//the original par value
Sometimes when using Visual Studio it displays a prompt with a filename: This file
sometimes I get the script execution error, where it takes over 30 seconds. It's
Sometimes I need the following pattern within a for loop. At times more than
Sometimes I start a MATLAB script and realize too late that it is going
Sometimes in execution I get this error message in VS2010 when trying to free
Sometimes, when I have a multi-case if , or a very simple for ,
Sometimes I get an exception like this: This method cannot be translated into a

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.