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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:16:52+00:00 2026-06-05T04:16:52+00:00

I have a structure named Foo which contains a unique_ptr struct Foo { std::unique_ptr<Bar>

  • 0

I have a structure named Foo which contains a unique_ptr

struct Foo {
    std::unique_ptr<Bar> pointer;
};

Now I’m trying to store instances of Foo in an unordered_map

std::unordered_map<int,Foo> myMap;

Technically this should be possible, since maps do not require a copy constructor, only a move constructor.

However, I can’t insert an element in my map:

myMap.insert(std::make_pair(3, Foo()));

This line will generate the following error in Visual C++ 2010 (roughly translated by me, since my compiler is not in english):

error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : unable to access private member declared in 'std::unique_ptr<_Ty>'  
with
[
             _Ty=Foo
]
c:\Softwares\Visual Studio 10.0\VC\include\memory(2347) : see declaration of 'std::unique_ptr<_Ty>::unique_ptr'
with
[
             _Ty=Foo
]
This diagnostic happened in the compiler-generated function 'Foo::Foo(const Foo&)'

So for an unknown reason, the compiler tries to generate a copy constructor for Foo instead of a move constructor, and fails.

I tried to replace std::make_pair with std::pair<int,something>, but can’t find any something which works.


EDIT : this works

struct Foo {
    Foo() {}
    Foo(Foo&& other) : pointer(std::move(other.pointer)) {}
    std::unique_ptr<Bar> pointer;
};

But my real structure contains a lot of members, and I don’t want to write all of them in the move constructor.

  • 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-05T04:16:53+00:00Added an answer on June 5, 2026 at 4:16 am

    MSVC10 (in Visual Studio 2010) doesn’t implement implicit move constructors yet (not surprising since implicit move constructors got into the standard quite late – there was a lot of discussion about it). They won’t be in MSVC11 (in the not-yet-released Visual Studio 2012) either.

    I would suggest using =default, but that’s not supported yet either.

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

Sidebar

Related Questions

I have a structure typedef struct store { char name[11]; int age; } store;
I have a file structure like so /foo/bar/ ├── .foo.cfg ├── foo.cfg ├── foo.data
I have a structure xyz with 3 string objects in it. foo bar and
Let's say I have a structure named vertex with a method that adds two
I have a table named friends with following structure: id, from_id, to_id, confirmed, ....
Hi, I have 20 strings, each of which will have same package structure except
We have a WSDL which contains the following type definition: ... <xsd:complexType name=OrderItem> <xsd:all>
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
I have a bag whose structure looks like this: <bag name=foo fetch=select table=table_of_foos> <key
I have this data structure: <estates version=0.1> <provider name=Foo> <estate id=12345678> <description>aaa</description> <size>300</size> </estate>

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.