Skip to content

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

Description

@chirsz-ever

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions