C ++ Acces违反读取错误 [英] C++ Acces violation reading error
问题描述
嘿,我正在编写一个C ++项目,该项目正在执行一些图形化转换.
我正在使用GPA.h类创建和管理像素数组,并使用Grid.h将较大的图片分解为较小的GPA类图片的网格.
函数Grid :: forge将多个GPA数组的网格绑定为一个更大的网格.
Hey, I''m writing a C++ project, that is performing some graphical trasnformations.
I''m using a GPA.h class to create and manage pixel-arrays and Grid.h to break a bigger picture into a grid of smaller GPA-class pictures.
The function Grid::forge binds a grid of multipple GPA arrays into a bigger one.
GPA Forge()
{
GPA Result=GPA(xtotal,ytotal);
for (int n=0;n<=X;n++){
for (int m=0;m<=Y;m++){
Result.Insert((*this)[n][m],0,0,n*xrange,m*yrange,xrange,yrange);
}
}
return Result;
}
它解决了函数GPA :: Insert
It addresses the function, GPA::Insert
void Insert (GPA Source,int xSource, int ySource,int xHere, int yHere, int xArea,int yArea)
{
for(int m=0;m<yArea;m++){
for(int n=0;n<xArea;n++){
(*this)[xHere+n][yHere+m]=Source[xSource+n][ySource+m];
}
}
}
但是,当我执行程序时,它在下面的行中中断并出现错误
However when I execute the program it breaks with a error on the following line
(*this)[xHere+n][yHere+m]=Source[xSource+n][ySource+m];
第一次执行.我还收到一个未处理的异常:访问冲突读取位置. (* this)[n] [m]变量的成员似乎未初始化,即使构造函数已被调用且变量已在
之前得到解决
有人知道为什么会发生这种情况吗?
在此先感谢
on first execution. I also get a Unhandled exception: Access violation reading location. The members of (*this)[n][m] variable appear to be not initialized, even if the constructer was called and the varaible has been addressed before
Anyone got an idea why it happens?
Thanks in advance
推荐答案
请执行此操作.
调试您的应用程序,然后执行以下语句:
Please do this thing.
Debug your application and when you come to the statement:
Result.Insert((*this)[n][m],0,0,n*xrange,m*yrange,xrange,yrange);
检查this [n] [m]的值,
因为那是
的第一个参数
check the value of this[n][m] ,
because that is what going as first argument to
void Insert (GPA Source,int xSource, ....)
,然后您尝试在语句
中访问
and which in turn your are trying to access in the statement
(*this)[xHere+n][yHere+m]=Source[xSource+n][ySource+m];
猜测您的程序中存在错误.找出为什么未正确初始化变量的唯一方法是在其上使用调试器.
At a guess there is a bug in your program. The only way to find out why your variables have not been initialised (properly) is to use the debugger on it.
这篇关于C ++ Acces违反读取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!