samedi 23 mai 2015

C++11 initializing std::vector of std::shared_ptr in constructor

I have a typedef of a vector of std::shared_ptr like so:

typedef std::vector<std::shared_ptr<Foo> > FooMap;

Then I have a Bar class with a FooMap member declared like:

FooMap _foos;

The Bar constructor looks like:

Bar::Bar(FooMap& foos) : _foos(foos) {}

I've also tried:

Bar::Bar(FooMap& foos) : _foos(std::move(foos)) {}

Neither will compile. I get:

error: no match for call to 
‘(FooMap {aka     std::vector<std::shared_ptr<Foo> >}) (FooMap&)’

or:

error: no match for call to 
‘(FooMap {aka std::vector<std::shared_ptr<Foo> >})
(std::remove_reference<std::vector<std::shared_ptr<Foo> >&>::type)

respectively.

Move constructors I'm still trying to figure out but I definitely can't understand why the first one doesn't just use the std::vector copy constructor.

What am I misunderstanding?

Aucun commentaire:

Enregistrer un commentaire