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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:07:20+00:00 2026-06-07T00:07:20+00:00

I tried writing this class #include <memory> class ContainerUnique { public: ContainerUnique(void); ~ContainerUnique(void); private:

  • 0

I tried writing this class

#include <memory>

class ContainerUnique
{
public:

    ContainerUnique(void);
    ~ContainerUnique(void);

private:
    std::unique_ptr<UniqueElement> u;
};

Where UniqueElement is a POD class defined elsewhere. I now define the constructor body like this:

ContainerUnique::ContainerUnique(void)
{
    auto tmp = new UniqueElement(1);

    this->u(tmp); // u is a unique_ptr<UniqueElement>. Should this call compile?
}

And it complies without exceptions. Running the program I find that after the constructor of ContainerUnique has been called, u contains a null pointer.

Is this the intended behaviour? And what unique_ptr method am I actually calling?

  • 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-07T00:07:21+00:00Added an answer on June 7, 2026 at 12:07 am

    This is a known problem with VS2010’s unique_ptr. It publicly inherits from its deleter if it’s empty as an optimization (empty base optimization). The downside to the public inheritance is that all members of the deleter also become available members of unique_ptr, in this case its operator()(T*) that deletes the pointer.

    The bug is fixed in VS2012’s library where the inheritance is changed to private.

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

Sidebar

Related Questions

While writing some code i came across this issue: #include <iostream> class random {
I have the following code to test memory deallocation using a std::list container: #include
I have a Mongoid model that looks like this: class V1Cache include Mongoid::Document field
I am writing a custom NSView subclass. I have several instances of this class
So I have tried to do this extensively but to no avail.. I'm writting
I tried writing a program in Java using regex to match a pattern and
I am having trouble creating an entity using inout ports. I tried writing the
I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
I have tried the following program for writing the contents into Spreadsheet. I downloaded
I was writing some codes in linux using c. When tried to compiled, I

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.