jeudi 5 avril 2018

std::shared_ptr use_count() value

Could someone please help me out why the output is 2 and not 3? Thank you.

int main()
{
    std::shared_ptr<int> x(new int);
    std::shared_ptr<int> const& y = x;
    std::shared_ptr<int> z = y;
    std::cout << x.use_count() << std::endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire