I am using MS Visual Studio 2019.
I have the following:
struct MyClass
{
std::vector<int> ints{};
std::map<int, int> map{};
};
struct MyMoveOnly
{
MyClass obj{};
MyMoveOnly() noexcept = default;
~MyMoveOnly() noexcept = default;
MyMoveOnly(const MyMoveOnly&) = delete;
MyMoveOnly(MyMoveOnly&& other) noexcept = default;
MyMoveOnly& operator=(const MyMoveOnly& other) = delete;
MyMoveOnly& operator=(MyMoveOnly&& other) noexcept = default;
};
And in my main I try to do a move as follows:
MyMoveOnly a{};
MyMoveOnly b = std::move(a);
This works fine if I comment out the map in MyClass so it only has a vector. But with the map I get this error when trying to compile: 'MyMoveOnly::MyMoveOnly(const MyMoveOnly &)': attempting to reference a deleted function
std::map is moveable so I don't get why this would happen. Is this the correct behavior or have I found a bug?