Qt在0x0处读取acces违规,标志= 0x0(第一次机会) [英] Qt read acces violation at:0x0, flags=0x0 (first chance)
本文介绍了Qt在0x0处读取acces违规,标志= 0x0(第一次机会)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段非常简单的代码,如下所示:
I have a very simple piece of code as follows:
Letter* Vakje::geefLetter() const
{
return m_letter;
}
Vakje类使用m_letter
的NULL指针初始化,但是我仍然收到读取访问冲突错误,有人可以帮忙吗?
The class Vakje gets initialized with a NULL-pointer for m_letter
, but I'm still getting a read access violation error, could someone please help?
这是调用该函数的代码:
this is the code that calls the function:
bool Spelbord::positionIsEmpty(int rij, int kolom) {
if (vakjes[rij][kolom]->geefLetter()==nullptr) return true;
else return false;
}
推荐答案
如果vakjes[rij][kolom]
是NULL
,则尝试取消引用指针->
会导致未定义的行为(通常是崩溃).
If vakjes[rij][kolom]
is NULL
, then trying to dereference that pointer ->
results in undefined behavior (usually: crash).
只需将代码更改为:
bool Spelbord::positionIsEmpty(int rij, int kolom) {
if (vakjes[rij][kolom] == nullptr) return true;
if (vakjes[rij][kolom]->geefLetter()==nullptr) return true;
return false;
}
这篇关于Qt在0x0处读取acces违规,标志= 0x0(第一次机会)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文