Copying a vector through constructor

I'm trying to copy another class' vector to cActionPuppet with the following code.
(I apologize for any formatting issues, for some reason, the site won't let me use the formatting tools)

1
2
3
4
5
6
cActionPuppet::cActionPuppet(std::vector< std::unique_ptr<ActionMove> > _cache)
	:cActor(),
	mActionMoveCache(_cache)
{

}


The general idea is that vector mActionMove copies the contents of _cache. Here's the declaration in cActionPuppet.h:

1
2
3
4
5
6
7
8
9
10
class cActionPuppet
	:public cActor
{
public:
	cActionPuppet(std::vector< std::unique_ptr<ActionMove> > _cache);

	void		updateCurrent(float dt, sf::Time _time);
	std::vector< std::unique_ptr<ActionMove> >			mActionMoveCache;

};


VS' intellisense returns no errors, but upon compiling, I get this error:

"Error 1 error C2280: 'std::unique_ptr<ActionMove,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' :
attempting to reference a deleted function C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0
"

Thanks in advance.
Last edited on
Simpler case: You want to make a copy of std::unique_ptr object. Does unique_ptr have copy constructor or copy assignment? If not, why?
I'm not trying to copy the ptr. I'm trying to copy the vector.
A vector that contains unique_ptr elements.
If I make a reference, then it would no longer copy the vector, which would go against what I'm attempting, here.
Last edited on
Something like this, perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <memory>
#include <vector>

struct action_move
{
    using pointer = std::unique_ptr<action_move> ;

    virtual ~action_move() = default ;

    // make a copy with dynamic storage duration and return a unique pointer to it
    virtual pointer clone() const { return std::make_unique<action_move>(*this) ; }
    // ...
};

struct move_randomly : action_move
{
    // override clone in derived classes (could use crtp if there are many derived classes)
    virtual pointer clone() const override { return std::make_unique<move_randomly>(*this) ; }
    // ...
};

struct action_puppet
{
    action_puppet( const std::vector<action_move::pointer>& cache )
    { for( const auto& ptr : cache ) action_move_cache.push_back( ptr->clone() ) ; }

    std::vector<action_move::pointer> action_move_cache ;
};
Registered users can post here. Sign in or register to post.