I saw that Shared pointer pass by value makes count as 0 on mac but remains as 1 on window for my code.
So I have been trying to understand shared pointer pass by value and pass by reference by listening to the talk reference talk . This was referenced in some other stack overflow link here
I have tried to understand the fundamentals by coding here https://godbolt.org/z/1vd53eEhM
#include <iostream>
#include <iostream>
#include <memory>
using namespace std;
void f(shared_ptr<int> sp) {
// Modify the reference count of the copy.
sp.reset();
}
int main() {
// Create a shared pointer.
shared_ptr<int> sp = make_shared<int>(10);
// Pass the shared pointer to the function by value.
f(sp);
// The original shared pointer has lost ownership of the object.
cout << "testing (should be 0) "<< sp.use_count() << endl; // Prints 0
return 0;
}
The expected output should have been 0 but I get it as 1.
What did I miss on the loss of the ownership part in pass by value?