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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:25:44+00:00 2026-06-11T04:25:44+00:00

I was reading through the wiki entry for c++11 and I found a section

  • 0

I was reading through the wiki entry for c++11 and I found a section for unrestricted union where you call placement new for the non-trivial memberlink, But the example here did not match that with a delete.

So my question is: do you need a placement delete for unrestricted union? If yes, how? If not, why? Would calling destructor suffice?

example:

class U_t
{
  public:
    union U
    {
        string s;
        U () { new (s) string(); }
    }
    U _data;
    ~U_t () { 
       _data.s.~string();
       //and now what?
    }
}
  • 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-11T04:25:46+00:00Added an answer on June 11, 2026 at 4:25 am

    § 9.5/2 If any non-static data member of a union has a non-trivial default constructor, copy constructor, move constructor, copy assignment operator , move assignment operator, or destructor, the corresponding member function of the union must be user-provided or it will be implicitly deleted for the union.

    § 9.5/3 Since std::string declares non-trivial versions of all of the special member functions, [the union] will have an implicitly deleted default constructor, copy/move constructor, copy/move assignment operator, and destructor. To use [the union], some or all of these member functions must be user-provided.

    § 9.5/4 In general, one must use explicit destructor calls and placement new operators to change the active member of a union.

    So yes, it requires a destructor call, similar to what you have.

    However, to use such a thing safely would be vastly more complex, since you’d have to constantly keep track of what type was active. To safely use a union with non-POD types is really hard. If I were you, only use PODs, or use boost::variant

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

Sidebar

Related Questions

I was reading through the TGA specification found at http://en.wikipedia.org/wiki/Truevision_TGA , and I found
Reading through documentation, I found following: 1.9.1 1.8.4 1.8.2 A version of 1.8.2 select
It's clear from reading through threads that I can call a PHP function using
Reading through the C specs I found this function: double remquo(double x, double y,
Just reading through the MSDN page about new .NET 4.0 feature SpinLock and can
Reading through a paper for the ARM Cortex-M3 CPU I found this line confusing:
Reading through an old blog post on SAP's community network, I found some instructions
While reading through javascript codes I've been seeing the ! operator used for non
Reading through the man page of the Linux system call sendfile , I am
Reading through this excellent article about safe construction techniques by Brain Goetz, I got

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.