如何返回2D数组并将其用于其他功能?

时间:2019-10-16 16:52:41

标签: c++ arrays pointers visual-c++

我正在尝试创建一个拼字游戏,我需要创建一个棋盘。我创建了具有mapTiles()作为其功能之一的Board类,它负责创建Board的基础,在正确的图块中插入单词/字母乘数。我希望此函数返回2d数组,以便可以在其他函数中使用它。 对于前。在我要执行的另一个功能上:

Board myBoard;
std::string array[15][15];
array = myBoard.array;

我尝试使用地图,指针,向量和2d数组,还有其他更有效的方法吗?

std::string tilesMap[15][15];

std::string mapTiles() {
    for (int cY = 0; cY < 15; cY++) {
        for (int cX = 0; cX < 15; cX++) {
            int cXY = cX + cY;
            double res = pow(cX, 2) + pow(cY, 2);
            tilesMap[cX][cY] = blank;

            if (cX == cY || cXY == 14) { // Sets the diagonals of the board with bonuses
                if (cX == 0 || cX == 14) { // 3 x Word
                    tilesMap[cX][cY] = x3W;
                }

                else if (cX == 5 || cX == 9) { // 3 x Letter
                    tilesMap[cX][cY] = x3L;
                }

                else if (cX == 6 || cX == 8) { // 2 x Letter
                    tilesMap[cX][cY] = x2L;
                }

                else {
                    tilesMap[cX][cY] = x2W; // 2 x Word
                }
            }

            else if (cXY % 7 == 0) {    // 3 x Word
                if (cY == 0 || cY == 7 || cY == 14) {
                    tilesMap[cX][cY] = x3W;
                }
            }

            else if (res == 26 || res == 82 || res == 194 || res == 250) { // 3 x Letter
                if (cY == 1 || cY == 5 || cY == 9 || cY == 13) {
                    tilesMap[cX][cY] = x3L;
                }
            }

            else if (res == 9 || res == 121 || res == 205 || res == 317) { // 2 x Letter outer ring
                if (cY == 0 || cY == 3 || cY == 11 || cY == 14) {
                    tilesMap[cX][cY] = x2L;
                }
            }

            else if (res == 40 || res == 68 || res == 180 || res == 208) { // 2 x Letter 2nd ring

                if (cY == 2 || cY == 6 || cY == 8 || cY == 12) {
                    tilesMap[cX][cY] = x2L;
                }

            }

            else if (res == 58 || res == 170) { // 2 x Letter 3rd ring
                if ((cY == 3) || (cY == 7) | (cY == 11)) {
                    tilesMap[cX][cY] = x2L;
                }
            }
        }
    }
    return tilesMap;
}

我得到的错误如下: 错误(活动)E0415不存在合适的构造函数,无法从“ std :: string [15] [15]”转换为“ std :: basic_string,std :: allocator>

0 个答案:

没有答案