Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hw4] Replace ill-formed assignment operator #1

Open
YangWithU opened this issue Jan 24, 2024 · 0 comments
Open

[Hw4] Replace ill-formed assignment operator #1

YangWithU opened this issue Jan 24, 2024 · 0 comments
Assignees

Comments

@YangWithU
Copy link
Owner

YangWithU commented Jan 24, 2024

The copy-assignment operator seems redudunt and ill-formed.
What if error was thrown during this->ref_counter = rhs.ref_counter; and this->base_ptr = rhs.base_ptr; ?
Find a better solution
Article as a guidance

template <typename T>
SharedPtr<T>& SharedPtr<T>::operator=(SharedPtr& rhs) {
    if(this != &rhs) {
        (*rhs.ref_counter) += 1;
        this->ref_counter = rhs.ref_counter;
        this->base_ptr = rhs.base_ptr;
    }
    return *this;
}
@YangWithU YangWithU self-assigned this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant