如何转置指针矩阵

问题描述 投票:1回答:1

我有一个布局矩阵

const int boatRect[MAX_BITMAP_SIZE][MAX_BITMAP_SIZE] = { // 5
        {0, 0, 1, 0, 0},
        {0, 0, 1, 0, 0},
        {0, 0, 1, 0, 0},
        {0, 0, 1, 0, 0},
        {0, 0, 1, 0, 0}
};

和具有指向它的指针的结构(矩阵):

typedef struct bitmap {
    Shape shape;
    const int (*matrix)[MAX_BITMAP_SIZE];
    int orientation;
    int size;
} Bitmap;

然后我想在结构中转置(旋转过程的一部分)矩阵:

void transpose(const int (*shape)[MAX_BITMAP_SIZE]) {
    const int *temp;
    for(int i = 0; i < MAX_BITMAP_SIZE; i++) {
        for(int j = 0; j < i; j++) {
            temp = (const int *) shape[i][j]; //Cast to 'const int *' from smaller integer type 'int'
            shape[i][j] = shape[j][i];        //Read-only variable is not assignable
            shape[j][i] = temp;               //Read-only variable is not assignable
        }
    }
}

但是我遇到那些错误,我不确定自己在做什么错!

我正在尝试以这种方式做到这一点,即在代码中仅包含一个矩阵,并具有指向它的指针,并以一种方式来旋转这些指针,使它们传达旋转的矩阵而不会创建另一个矩阵]

我有一个布局矩阵const int boatRect [MAX_BITMAP_SIZE] [MAX_BITMAP_SIZE] = {// 5 {0,0,1,0,0},{0,0,1,0,0},{0, 0,1,0,0},{0,0,1,0,0},{...

c arrays pointers matrix const
1个回答
0
投票

您的矩阵不是“指针矩阵”,它是一个以指针为元素的矩阵。这是一个整数矩阵。您将其定义为int的数组。

© www.soinside.com 2019 - 2024. All rights reserved.