I was wondering why my native pointer is still able to access my object after the memory should be freed?
#include <iostream>
#include <memory>
using namespace std;
class A
{
public:
int a_;
double b_;
A(int a, double b) : b_(b), a_(a)
{}
};
int main() {
auto s_ptr = make_shared<A>(3,3.3);
A* n_ptr = s_ptr.get();
cout << n_ptr->b_ << endl;
s_ptr.reset();
cout << n_ptr->b_ << endl;
return 0;
}
The output is:
3.3
3.3
Maybe the memory is freed but still stores the same values. In this case, how can I verify if an object still exists?
Thanks!