struct Test
{
Test() {};
Test(const Test&) = delete;
Test& operator=(const Test&) = delete;
};
int main(int argc, char* argv[])
{
std::vector<Test> tests;
tests.push_back(std::move(Test())); //gives error here
return 0;
}
gives me error: error C2280: 'Test::Test(const Test &)': attempting to reference a deleted function
I know that I've explicitely deleted copy constructor, but I thought I could move instance of Test() to vector insteasd of copying it. What am I doing wrong? How to move Test() to vector?
Deleting copy constructor explicitely caused compiler to not generate move constructor.
So calling std::move(Test()) does not call move constructor because there is no one.
But in that case, shouldn't compiler inform me that move constructor is missing?
> But in that case, shouldn't compiler inform me that move constructor is missing?
If only the copy constructor is provided, all argument categories select it (as long as it takes a reference to const, since rvalues can bind to const references), which makes copying the fallback for moving, when moving is unavailable.