I'm trying to make a move operator for a class (which we will call A
) that contains another reference to another class (which we will call B
), whose copy constructor has been implicitly deleted because it contains another reference. A simple example has been shown below.
class B
{
public:
int & num;
B(int & _num) : num(_num) {}
};
class A
{
public:
B & b;
A(B & _b) : b(_b) {}
A & operator=(A && other)
{
b = other.b; //< Error
return *this;
}
};
When I try to compile, I get this error:
error: object of type 'B' cannot be assigned because its copy assignment operator is implicitly deleted b = other.b;
A couple of questions:
1) Why is the implicit copy assignment operator deleted in B
? Or even A
for that matter?
2) Why does it matter if B
has a copy constructor or operator if I'm trying to copy the reference, not the object? Am I not doing that part right?