The class Foo has an rvalue reference constructor that moves the contained vector of unique_ptr
s so why does the following code give the following error, both with or without the std::move
on the Foo()
in main
?
error C2280: 'std::unique_ptr<SomeThing,std::default_delete<_Ty>> &std::unique_ptr<_Ty,std::default_delete<_Ty>>::operator =(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function
class Foo{
public:
Foo(){
}
Foo(Foo&& other) :
m_bar(std::move(other.m_bar))
{};
std::vector<std::unique_ptr<SomeThing>> m_bar;
};
int main(int argc, char* argv[])
{
Foo f;
f = std::move(Foo());
return 0;
}