指向对象内存位置的指针已在程序中删除,但仍提供正确答案而不是垃圾值

The pointer to memory location to the object has been deleted in program but still provides the correct answer and not garbage value

指针 *sbi 内存已使用删除运算符释放,但代码仍能正确执行而无需提供垃圾值。是构造函数重新初始化还是代码中的错误/

#include <iostream>
using namespace std;

class bank
{
private:
    int balance;
public:
    bank();
    void dep(int x);
    void with();
    ~bank();
};
int main()
{
    bank *sbi;
    sbi = new bank;
    sbi->dep(50000);
    delete sbi;   /// problem is in this section of code 
    sbi->with();
    return 0;
}

bank :: bank()
{
    balance=0;
}

void bank::dep(int x)
{
    balance=x;
}

void bank::with()
{
    cout<<balance<<endl;
}

bank::~bank()
{
    cout<<"destroy"<<endl;
}

释放内存位置不会自动用垃圾覆盖它。巧合的是,余额中存储的值仍然相同。