Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++/错误::exc\u错误\u访问错误代码=1_C++_Pointers_Runtime Error_Exc Bad Access - Fatal编程技术网

C++ c++/错误::exc\u错误\u访问错误代码=1

C++ c++/错误::exc\u错误\u访问错误代码=1,c++,pointers,runtime-error,exc-bad-access,C++,Pointers,Runtime Error,Exc Bad Access,我得到一个运行时错误的exc_坏_访问(代码=1,地址=0x0)在线 在求和函数中。 我知道问题不是内存泄漏,所以我不太知道如何着手解决这个问题 void allocArr (int **&x, int ***&y, int **&q, int ****&z) { x = new int *[2]; y = new int **(&*x); q = &*x; z = new int ***(&q); } v

我得到一个运行时错误的exc_坏_访问(代码=1,地址=0x0)在线

在求和函数中。 我知道问题不是内存泄漏,所以我不太知道如何着手解决这个问题

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.)括号运算符的优先级高于取消引用运算符。(将它们括在括号内几乎总是一个好主意)。按照写入方式,括号运算符将在deref之前执行。
3.)您需要这么多解引用运算符,这似乎很不寻常。它们真的是必要的吗?

使用此代码,您到底想实现什么?这东西的恒星比银河系多。你能解释一下你想做什么吗?这看起来像是******的一些真正无关的用法。y似乎在任何点上都没有设置为值。我试图将y指向的数组中的值存储在变量asize中。遗憾的是,这个程序的整个要点是使用多级间接寻址,正如我的教授所指定的。
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);


}