class sphere {
int radius;
public:
sphere(int r){
radius = r;
}
void setRadius(int r) {
radius = r;
}
int getRadius() {
return radius;
}
};
int main()
{
sphere *a, *b;
a = new sphere(1);
b = a;
delete b;
cout << a->getRadius() << endl;
return 0;
}
This code actually prints out 1
on the console. According to this post, the sphere with radius 1 should have been deleted.
My question is:
Why is it not returning a SegFault? I am expecting a SegFault because since the sphere is deleted, ->getRadius
wouldn't be available for a
anymore.