关于数组传递的错误

unsigned char* getDirectionGray( unsigned char** ptrCenterRow, int j)
{
    unsigned char p[4]; //如果修改成*p则出现段错误,还没搞懂

    p[0] = abs(ptrCenterRow[-1][(j-1)] -ptrCenterRow[0][j]) +
                        abs(ptrCenterRow[1][(j+1)]-ptrCenterRow[0][j]);   
    cout << "d0:" << p[0] <<  endl;
    printf("%d\n", p[0]);
    p[1] = abs(ptrCenterRow[-1][j]-ptrCenterRow[0][j])+
                        abs(ptrCenterRow[1][j]-ptrCenterRow[0][j]);
    cout << "d1:" << p[1] << endl;
    printf("%d\n", p[1]);
    p[2] = abs(ptrCenterRow[1][(j+1)]-ptrCenterRow[0][j]) + 
                        abs(ptrCenterRow[1][(j-1)]-ptrCenterRow[0][j]);
    cout << "d2:" << p[2] << endl;
    printf("%d\n", p[2]);
    p[3] = abs(ptrCenterRow[0][(j-1)]-ptrCenterRow[0][j]) + 
                        abs(ptrCenterRow[0][(j+1)] - ptrCenterRow[0][j]);
    cout << "d3:" << p[3] << endl;
    printf("%d\n", p[3]);
    cout << "getDirectionGray()" << endl;
    return p;

}

猜你喜欢

转载自www.cnblogs.com/Shinered/p/10494922.html