Why is it when reference counting, the copy-constructor increments this->counter but the copy-assignment increments ++*rhs.counter?
I am unable to work out in my head reasons for such. I understand that the std::shared_ptr increments the counter on both copy and assign.
Well, in the assignment operator, before the assignment has taken place, incrementing the current objects counter would addref the wrong object. After the assignment happens it could addref the current object, but addrefing the right hand side is safer because it can be done before or after. All else being equal, it's therefore better to addref the right hand side. It quite possibly doesn't matter though, as long as this happens after the pointer assignment.
Thank you for your reply. Per my text, reference count increment/decrement happens prior to pointer assignment.
Right so you understand why now then?
Yes and thank you.
Originally Posted by iMalc