dimanche 30 août 2015

Why doesn't changing the value of the object that is pointed doesn't change in shared_ptr?

While using raw pointer if you changed the value of the object that is pointed the pointer's value while dereferecing also changes. But while using shared_ptr that is not the case. Why is it so?

    int i = 3; 
    shared_ptr<int> q = make_shared<int>(i);
    //  what i want "int*q = &i;"
    i = 5;
    cout << *q << endl; //isn't it suppose to print 5

Aucun commentaire:

Enregistrer un commentaire