【发布时间】:2013-11-02 18:25:51
【问题描述】:
我有一个函数func(),它接受一个双指针。如果它指向零,则函数退出(第一次检查)。现在没有第二次检查,我在尝试访问 mybar 的成员时遇到访问冲突(仅当我第二次运行该函数时)。这是为什么?如果mybar == NULL 不应该在第一次检查时退出?
func( Foo **bar )
{
//First check
if(bar== NULL)
return;
Foo *mybar = *bar;
//Second check
if(mybar == NULL)
return;
if(mybar->member != NULL) //Access violation here if I dont have the 'second check'
{
//do stuff
}
delete mybar;
*bar = NULL;
}
我就是这么称呼它的:
Foo *bar = NULL;
initialize(&bar);
func(&bar);
func(&bar); //Second time I call it, I get the access violation
【问题讨论】:
-
显示你如何调用函数
-
@claptrap 谢谢,我加了电话。实际上,当我第二次调用它时它会爆炸。我想证明它,这样我才能真正调用它第二次,它只是返回而没有访问冲突。
-
向你展示initialize()函数。