[英]c++/error :: exc_bad_access error code=1
我在行上獲得了exc_bad_access(代碼= 1,地址= 0x0)的運行時錯誤
asize = **y[0] + **y[1];
在求和函數中。 我知道問題不是內存泄漏,所以我不太了解如何解決此問題。
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.)您似乎需要很多取消引用運算符似乎很不尋常。 他們真的有必要嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.