如何在函数中将数组成员作为参数传递,C++

How to pass members of arrays as parameters in functions, C++

我是 C++ 的新手,正在尝试为游戏创建一个简单的地图(我使用的是 sfml)。

我正在创建一个白色矩形数组,我想将数组成员作为参数传递给函数调用。

例如:

Sprite WallSprites[10];
    for (int i = 0; i < 10; i++) {
        WallSprites[i].setTexture(Wall);
        WallSprites[i].scale(0.3, 0.6);
    }

WallSprite[0].setPosition(400,300);

while (window.isOpen())
    {
        window.clear();
        window.draw(WallSprite[0]);
        window.display();
    }

上面的代码无法编译,我不确定如何从这里开始。我很确定我没有正确实施这些概念;任何帮助将不胜感激。谢谢!

我注意到您的代码中有一个拼写错误会阻止它编译:

WallSprite[0].setPosition(400,300);

while(window.isOpen())
    {
        window.clear();
        window.draw(WallSprite[0]);
        window.display();
    }

应该是:

WallSprites[0].setPosition(400,300); // Forgot the 's' in 'WallSprites'

while(window.isOpen())
    {
        window.clear();
        window.draw(WallSprites[0]); // Forgot the 's' in 'WallSprites'
        window.display();
    }