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

Should we take care of the safe bool problem? #9

Open
chirsz-ever opened this issue Apr 5, 2022 · 0 comments
Open

Should we take care of the safe bool problem? #9

chirsz-ever opened this issue Apr 5, 2022 · 0 comments

Comments

@chirsz-ever
Copy link
Contributor

Currently shared_ptr and unique_ptr use implicit operator bool to be convertible to a bool value.

This causes some problems, such as:

shared_ptr<int> p(new int(10));
// ...
int x = p;

In this case p would be converted to a bool value and than converted to a int value, 0 or 1.

A better way is to define operator! and operator void*.

See: https://en.cppreference.com/w/cpp/language/implicit_conversion

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