我在行上获得了exc_bad_access(代码= 1,地址= 0x0)的运行时错误
Im getting a runtime error of exc_bad_access ( code = 1, address=0x0) on line
asize = **y[0] + **y[1];求和函数中的
. 我知道问题不是内存泄漏,所以我不太了解如何解决此问题.
in the summation function. I know the problem is not a memory leak, so i don't quite know how to go about solving this problem.
void allocArr (int **&x, int ***&y, int **&q, int ****&z) { x = new int *[2]; y = new int **(&*x); q = &*x; z = new int ***(&q); } void summation(int ***&y, int arr[]) { int asize = 0; asize = **y[0] + **y[1]; **y[2] = *new int [asize]; *(arr + 2) = asize; } void putArr(int **&x, const int &size1,const int &size2) { x[0] = *new int* [size1]; x[1] = *new int* [size2]; } int main() { int size1, size2; int a = 1, b = 2; int** x; int*** y; int** q; int**** z; int arr[2]; allocArr(x, y, q, z); Input(x, arr, size1, size2, a, b); summation(y, arr); display(z); }谢谢您的帮助.
推荐答案三件事. 1.)y的函数参数为int * & .您是否在其他地方用方括号运算符重载了int?如指定的那样,int指针不应包含[]. 2.)括号运算符的优先级比取消引用运算符的优先级高. (将它们放在括号内几乎总是一个好主意).编写方式,方括号运算符将在反引用之前执行. 3.)您似乎需要这么多的取消引用运算符似乎很不寻常.他们真的有必要吗?
Three things. 1.)The function arguments for y are int *& . Did you overload int with a bracket operator somewhere else? As specified, the int pointer should not have a []. 2.) Bracket operators are higher in precedence than a dereference operator. (Almost always a good idea to enclose them within parenthesis). The way this is written, the bracket operator will be performed before the deref. 3.) It seems unusual that you should need so many dereference operators. Are they really necessary?
更多推荐
c ++/错误:: exc
发布评论