I'd like to have a vector of unique_ptr's as a member of a class I'm making.
class Foo {
[...]
private:
vector<unique_ptr<Bar>> barList;
}
But then I start getting cryptic error messages from the VS2010 compiler:
error C2248: 'std::unique_ptr<_Ty>::operator =' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
Along with a handful of error lines below that which dive into Microsoft's implementation of std::_Copy_impl<>
...
I changed the member declaration to
vector<unique_ptr<Bar>>* barList;
And it compiles. But I can't help but wonder why I can't do it the way I originally wanted? For grins, I tried this and it works fine:
vector<Bar> barList;
But now I lose the convenience of unique_ptr
. I want my cake and I want to eat it too!
vector
like I did is just fine to do. For some reason, though, it seems to trigger illegal copies when adding theunique_ptr
part. – Ningsiaunique_ptr
toshared_ptr
when I realized I was using the wrong ownership semantic. – Ningsia