I have a piece of code that looks something like this:
class B
{
private:
const A& obj;
size_t val;
// private - prohibited
B& operator=(const B& other);
public:
B(const A& obj_): obj(obj_)
{
val = 0;
}
};
class C
{
void func()
{
A a1;
B b1(a1);
B b2 = b1; // should throw error?
}
}
Class B has a private assignment operator. Nonetheless assignment in C::func() compiles without errors. But how?
b2is a new object so it's being constructed.B b2 = b1;looks like an assignment but is not, it's only uses a constructor. This can be confusing when first encountered.