为什么我不能正确使用我的2D数组RectangleShapes?

时间:2017-10-30 03:44:27

标签: c++ arrays

这是我的drawTile函数。在这里,我声明了我的2d RectangleShapes数组,我将相同的RectangleShape r传递到每个位置。

void board::drawTile(RenderWindow &window, int x2, int y2){
    RectangleShape r;

    RectangleShape rectArray[y2][x2]; //I've already defined rectArray above in my class

    for(int i2 = 0; i2 < y2; i2++){
        for(int ii2 = 0; ii2 < x2; ii2++){
            rectArray[i2][ii2] = r;
        }
    }
}

当我这样做时,它会给我以下错误:

"no match for operator[]' (operator types are 'sf::RectangleShape' and 'int').

我无法说出错误。

int main(){ 
    RenderWindow window(VideoMode(800,800), "Window");
    x = 10;
    y = 10;
    board callFunc;
    board rectArrayObj;
    callFunc.drawTile(window, x, y);
    rectArrayObj.rectArray[column][row].setFiilColor(Color::Red);
}

0 个答案:

没有答案