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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:34:24+00:00 2026-06-01T22:34:24+00:00

VS2010 I have a structure that has a unique_ptr inside. I then have a

  • 0

VS2010

I have a structure that has a unique_ptr inside. I then have a vector of this structure. If I try to resize (or use reserve on) the vector, I get compilation errors. Below is a stripped-down example that still exhibits the problem.

struct Test
{
    unique_ptr<int> pValue;
};

void test()
{
    // this doesn't compile
    vector<Test> testVector;
    testVector.resize(5);

    // this also doesn't compile
    testVector.reserve(5);

    // this, of course, compiles
    vector<unique_ptr<int>> testVector2;
    testVector2.resize(5);
    testVector2.reserve(5);
}

The errors I get are complaints about accessing private members of unique_ptr (the assignment operators). The compiler is trying to dynamically construct Test &Test::operator =(const Test &) and Test::Test(const Test &). I don’t see why a resize operation would need to call either of these functions (why doesn’t it just call the default constructor if it needs to?). Both of them present problems because it isn’t possible to make either with unique_ptr due to the const.

  • 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-01T22:34:26+00:00Added an answer on June 1, 2026 at 10:34 pm

    I hate to interrupt this conversation you’re having with yourself. 🙂

    But the answer is that VS2010 does not yet fully implement the C++11 spec (which would require a bit of time travel). Test should have a defaulted noexcept move constructor that calls the unique_ptr move constructor. VS2010 does not implement this implicit Test move constructor. If it did, your complete example would compile and run as expected. vector will use noexcept move constructors to move things around when it needs to.

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

Sidebar

Related Questions

I'm using MVC2 with VS2010 I have a view that has two partial views
I have inhherited a vs2010 c# web project (asp.net). It has a web reference
I have created a DeclarativeServiceLibrary using VS2010 beta 2, Please check this image of
I have the RC build of VS2010 installed on my computer. Now that the
I have an MVC 2.0 application that I'm playing around with in VS2010 which
I am using the build in publishing tools of VS2010. I use this for
Using VS2010 i have a test that calls a method which runs a command
I have VS2010 Professional installed A client has recently asked me to add a
I have VS2010 professional that I got from DreamSpark website. Now I'd like to
I have built a dll with VS2010 targeted for framework 4.0. When I try

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.