Suppose, I have the following code. There's a copy constructor in B which calls a method which copies the resources of a.
Now I also have a move constructor. In this case, a should not be copied but just "steal" the resources from an existing a. Therefore, I also implemented an init taking an rvalue. But of course, when I try to call it with parameter b.a, this is an lvalue...
Is there a way to call this method?
class A{
A(const A&& a){
// 'steal' resources from a
}
void init(A& a){
// init this A from another A by copying its resources
}
void init(A&& a){
// init this A from another A stealing its resources and tell the other a, it must not destroy resources upon destruction
}
};
class B{
A a;
B(B& b){
a.init(b.a)
}
B(B&& b){
a.init(b.a); // How to call init(A&& a)?
}
};