当我尝试以下代码时,似乎“删除”(C++ 中的空闲内存)不起作用......好吧,我知道该引用不适合“引用稍后将被释放的对象”。我只是在玩代码..
class A{
public:
int val;
A(int val_=0):val(val_){}
};
A* ptrA = new A(10);
A &refA = *ptrA;
printf("%d\n", refA.val);
delete ptrA;
refA.val = 100;
printf("%d\n", refA.val);
输出为:10 100