vendredi 26 février 2021

Shared pointer confusion

I'm currently learning the smart pointers and I got a bit confused. Why the shared pointer does not print the memory address that stores as raw pointer neither with simple print nor with get() ?

int x = 100;
int* y = &x;
std::cout<<&x<<std::endl;
std::cout<<y<<std::endl;

std::shared_ptr<int> x2 = std::make_shared<int>(x);
std::cout<<x2.get()<<std::endl


0x7ffe965e20b4                                                                                                       
0x7ffe965e20b4                                                                                                       
**0x2176c30**  so why this value is for both x2.get() and x2 ? 

Thank you

Aucun commentaire:

Enregistrer un commentaire