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

bugfix:smart_ptr拷贝函数实现 #2

Open
Playerfff opened this issue Apr 15, 2024 · 0 comments
Open

bugfix:smart_ptr拷贝函数实现 #2

Playerfff opened this issue Apr 15, 2024 · 0 comments

Comments

@Playerfff
Copy link

template
smart_ptr::smart_ptr(const smart_ptr& rhs)
:m_pobject(rhs.m_pobject), m_p_use_count(rhs.m_p_use_count), m_del(rhs.m_del)
{
(*m_p_use_count)++;
}
如果调用这个函数,例如:smart_ptr ptr2(ptr1);
只有ptr2的引用计数会加1,ptr1的引用计数没变,我觉得有问题,应该ptr1和ptr2使用一块memory作为引用计数,确保ptr2在增加引用计数时ptr1的引用计数也会变。

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