想象一下,我们有一个范围,其中定义了一个变量,一个范围较大的指针获得了该变量的引用。当我们离开范围知道指针是在外部作用域中定义时会发生什么,例如类成员。
{
int a = 6;
pointa = &a; //defined out of this scope
}
//what happens here, pointa is still defined in this scope
编辑:我的问题是关于一个更具体的案例,我无法找到答案(感觉就像答案在于悬挂指针的解释)。
假设foo()是一个返回double的函数。 我试过这个:
int* p;
p = &foo();
然后p变空了。 你能解释一下这与悬垂指针的关系吗?
答案 0 :(得分:0)