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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:51:36+00:00 2026-05-14T08:51:36+00:00

#include <vector> #include <memory> using namespace std; class A { public: A(): i(new int)

  • 0
#include <vector>
#include <memory>

using namespace std;

class A {
public:
    A(): i(new int) {}
    A(A const& a) = delete;
    A(A &&a): i(move(a.i)) {}

    unique_ptr<int> i;
};

class AGroup {
public:
    void                    AddA(A &&a) { a_.emplace_back(move(a)); }

    vector<A> a_;
};

int main() {
    AGroup ag;
    ag.AddA(A());
    return 0;
}

does not compile… (says that unique_ptr’s copy constructor is deleted)

I tried replacing move with forward. Not sure if I did it right, but it didn’t work for me.


[~/nn/src] g++ a.cc -o a -std=c++0x
/opt/local/include/gcc44/c++/bits/unique_ptr.h: In member function 'A& A::operator=(const A&)':
a.cc:6:   instantiated from 'void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, _Args&& ...) [with _Args = A, _Tp = A, _Alloc = std::allocator<A>]'
/opt/local/include/gcc44/c++/bits/vector.tcc:100:   instantiated from 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = A, _Tp = A, _Alloc = std::allocator<A>]'
a.cc:17:   instantiated from here
/opt/local/include/gcc44/c++/bits/unique_ptr.h:219: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>& std::unique_ptr<_Tp, _Tp_Deleter>::operator=(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = int, _Tp_Deleter = std::default_delete<int>]'
a.cc:6: error: used here
In file included from /opt/local/include/gcc44/c++/vector:69,
                 from a.cc:1:
/opt/local/include/gcc44/c++/bits/vector.tcc: In member function 'void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, _Args&& ...) [with _Args = A, _Tp = A, _Alloc = std::allocator<A>]':
/opt/local/include/gcc44/c++/bits/vector.tcc:100:   instantiated from 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = A, _Tp = A, _Alloc = std::allocator<A>]'
a.cc:17:   instantiated from here
/opt/local/include/gcc44/c++/bits/vector.tcc:314: note: synthesized method 'A& A::operator=(const A&)' first required here
  • 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-14T08:51:36+00:00Added an answer on May 14, 2026 at 8:51 am

    Probably your standard library doesn’t (yet) define unique_ptr<T>::unique_ptr(unique_ptr &&). I checked my headers in 4.5 and it’s there, so maybe try upgrading.

    When it fails to find the move constructor, it would look for the copy constructor and find it deleted.

    I get other errors when I compile that, though.

    EDIT: Got it to work. I don’t understand why you have to move an object which is already an rvalue reference, but you do. The only problem was a missing assigment operator.

    #include <vector>
    #include <memory>
    
    using namespace std;
    
    class A {
    public:
        A(): i(new int) {}
        A(A const& a) = delete;
        A &operator=(A const &) = delete;
        A(A &&a): i(move(a.i)) {}
        A &operator=(A &&a ) { i = move(a.i); }
    
        unique_ptr<int> i;
    };
    
    class AGroup {
    public:
        void                    AddA(A &&a) { a_.emplace_back(move(a)); }
    
        vector<A> a_;
    };
    
    int main() {
        AGroup ag;
        ag.AddA(A());
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code snippet: #include <vector> using namespace std; void sub(vector<int>& vec) {
Consider the following code: #include <iostream> #include <memory> #include <vector> using namespace std; struct
#include <iostream> using namespace std; // This first class contains a vector and a
#include <iostream> #include <vector> using namespace std; int main(void) { int i, s, g;
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
Consider this piece of code: #include <vector> #include <iostream> using namespace std; class Base
#include <iostream> #include <vector> #include <list> using namespace std; int main() { vector<list<string> >
#include <stdlib.h> #include <iostream> #include <vector> #include <string> class A { public: std::string s;
The following piece of code #include <iostream> #include <vector> #include <tuple> using namespace std;
#include <iostream> #include <vector> using namespace std; typedef struct Record { std::string name; bool

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.