The function below works with the return type Class, Class& and void. So, what's the difference between each?
//deep copies one object into another
Club& Club::operator= (Club& obj) {
this->members_ = std::unique_ptr <Member[]> (new (std::nothrow) Member[obj.num_members_]);
if (members_ != nullptr) {
this->num_members_ = obj.num_members_;
for (int i = 0; i < obj.num_members_; i++) {
this->members_[i] = obj.members_[i];
}
}
else {
std::cout << "Memory could not be allocated.\n";
this->num_members_ = 0;
}
return *this;
}
My professor told me to return by value but I dont understand why we need to return anything?
In the main file,
club200 = club200a;
As we are directly making changes to the variables pointed by this, why do we need to return the address or the value? We're not storing the returned value anywhere.
Also, I understand that reference is used to chain the operator but what's really happening to the returned value?