c ++/错误:: exc

编程入门 行业动态 更新时间:2024-10-10 02:17:32
本文介绍了c ++/错误:: exc_bad_access错误代码= 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在行上获得了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

本文发布于:2023-11-26 19:21:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   exc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!