Sobes.tech
Middle — Senior

Increment of link counter during copy assignment

livecode

Task condition

It is necessary to implement the increment of the reference counter in the assignment operator of the custom smart pointer CustomSharedPtr.

CustomSharedPtr& operator=(const CustomSharedPtr& p) {
    if (p.resource != this->resource) {
        ~CustomSharedPtr();
        this->resource = p.resource;
        this->refCount = p.refCount;
    }
    return *this;
}