We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Currently shared_ptr and unique_ptr use implicit operator bool to be convertible to a bool value.
shared_ptr
unique_ptr
operator bool
bool
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.
p
int
0
1
A better way is to define operator! and operator void*.
operator!
operator void*
See: https://en.cppreference.com/w/cpp/language/implicit_conversion
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Currently
shared_ptr
andunique_ptr
use implicitoperator bool
to be convertible to abool
value.This causes some problems, such as:
In this case
p
would be converted to abool
value and than converted to aint
value,0
or1
.A better way is to define
operator!
andoperator void*
.See: https://en.cppreference.com/w/cpp/language/implicit_conversion
The text was updated successfully, but these errors were encountered: