[英]Pointer Access Violation issue
i know a ton of these questions appear, but i have tried/searched everything to no avail. 我知道会出现很多这样的问题,但是我尝试/搜索了所有方法都无济于事。
UPDATE START 更新开始
Test Class 测试班
#include "stdafx.h"
#include "testerClasser.h"
Tester::Tester(){
}
void Tester::GetNum(int * num){
int num2 = 6;
*num = num2;// error thrown here
}
an example of calling GetNum function 调用GetNum函数的示例
int _tmain(int argc, _TCHAR* argv[])
{
int* num = NULL;
Tester* tester = new Tester();
tester->GetNum(num);
return 0;
}
error Unhandled exception at 0x77c115de in Tester.exe: 0xC0000005: Access violation writing location 0x00000000. 错误Tester.exe中0x77c115de的未处理异常:0xC0000005:访问冲突写入位置0x00000000。 UPDATE END
更新结束
i have a method 我有办法
void CCCamera::getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ) {
*pEyeX = m_fEyeX; *pEyeY = m_fEyeY; *pEyeZ = m_fEyeZ;
}
i have tried to call the method 我试图调用该方法
float* pEyeX = new float(10);
float* pEyeY= new float(10);
float* pEyeZ= new float(10);
this->m_pCamera->getEyeXYZ (pEyeX,pEyeY,pEyeZ);
and 和
float* pEyeX;
float* pEyeY;
float* pEyeZ;
this->m_pCamera->getEyeXYZ (pEyeX,pEyeY,pEyeZ);
even 甚至
float pEyeX;
float pEyeY;
float pEyeZ;
this->m_pCamera->getEyeXYZ (&pEyeX,&pEyeY,&pEyeZ);
their is obviously something i am missing can anyone help ? 他们显然是我所缺少的东西,谁能帮忙?
In the following code you are trying to dereference a NULL
pointer inside GetNum
function. 在下面的代码中,您尝试在
GetNum
函数中取消引用NULL
指针。
int _tmain(int argc, _TCHAR* argv[])
{
int* num = NULL;
Tester* tester = new Tester();
tester->GetNum(num); //will result in NULL pointer dereference inside GetNum!
return 0;
}
What you need is most likely the following: 您最需要的是以下内容:
int _tmain(int argc, _TCHAR* argv[])
{
int num = 0;
Tester* tester = new Tester();
tester->GetNum(&num); // pass a pointer to local variable
return 0;
}
So what's the question? 那是什么问题呢?
The first block works, the second block does not (pointers pointing 'nowhere', which doesn't actually exist in programming so they are just pointing to more-or-less random locations), the third block is fine again. 第一个块起作用,第二个块不起作用(指向'nowhere'的指针,在编程中实际上并不存在,因此它们只是指向或多或少的随机位置),第三个块也很好。
The first thing to do would be to figure out which pointer is causing the issue. 首先要做的是找出导致问题的指针。 The symptoms that you reported strongly suggest that there's something wrong with your
this
or this->m_pCamera
pointers. 您强烈报告的症状表明
this
或this->m_pCamera
指针有问题。 Trying to play with parameter pEye...
pointers will make no difference because they probably have nothing to do with the issue at all. 尝试使用参数
pEye...
指针将没有任何区别,因为它们可能与该问题完全无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.