Please read updates for clarification.
Suppose there is a class Resource that handles acquisition and release of some resource.
Now I have my class
class MyClass{
public:
MyClass(){};
MyClass(MyClass&& other){
...
}
private:
Resource r1;
Resource r2;
}
The problem is when the move constructor is called, the resources r1 and r2 are already acquired. But I don't need them if I'm going to move the resources from other object.
What am I getting wrong?
Update: Resource supports move and is not copiable.
Update 2: First there was some misunderstanding about the Resource class. I didn't post its implementation because I supposed it would be pretty regular one. The class acquires a resource on creation and releases on destruction). The class is movable. I think most resource handling classes are of that kind.
The real problem was that I tought I need to implement some sort of copy-and-swap. But the idiom seems to work well when you manage a resource yourself. If you use a ready RAII class for resources, then copy-and-swap will not work. Correct me if I'm wrong again.
So, with help of JohnFilleau's comment I came to the following code:
class MyClass{
public:
MyClass(){};
MyClass(MyClass&& other): r1(std::move(other.r1)), r2(std::move(other.r2)){};
private:
Resource r1;
Resource r2;
}