0

C++ でグリッドを反復処理し、すべての座標を false としてマークしようとしています。私がやったと思ったのは、25x25 グリッドを作成することでしたが、VC++ で 2 つのエラーが発生しました。

(37)"error C2064: term does not evaluate to a function taking 0 arguments"

(44)"error C2448: 'markAllIncluded' : function-style initializer appears to be a function definition"

一部のヘッダー ファイルにスタンフォード C++ ライブラリを使用しています。

これが私のコードです:

#include <iostream>
#include "console.h"
#include "maze.h"
#include "gwindow.h"
#include "grid.h"
#include "queue.h"
#include "random.h"
#include "simpio.h"
#include "stack.h"
#include "vector.h"
#include <array>

using namespace std;
//prototypes

const int numCols = 25;
const int numRows = 25;

Vector<int> rand_coords();
Grid<bool> markAllIncluded(numCols, numRows);

int main() {

    Vector <int> coords = rand_coords(); //get random coords
    cout << "(" << coords[0] << ", " << coords[1] << ")" << endl;


    Grid<bool> included = markAllIncluded();
    string x = included.toString();
    cout << x;

    return 0;
}

Grid<bool> markAllIncluded() {

    Grid<bool> m(numRows, numCols); 

    for (int i=0; i <= numRows; i++) {
        for (int j = 0; j <= numCols; j++) {
            m.set(i, j, false);
        }
    }

    return m;

}


Vector<int> rand_coords () {

    Vector<int> coords(2);

    coords[0] = randomInteger(0, numCols);
    coords[1] = randomInteger(0, numRows);

    //cout << "(" << coords[0] << ", " << coords[1] << ")" << endl;

    return coords;

}

私の構文は間違っていますか?include を markAllIncluded()l に設定すると、main() でエラーが発生します。

4

1 に答える 1

1

ええ、あなたの構文は間違っています。関数宣言

Grid<bool> markAllIncluded(numCols, numRows);

間違っています。使用する必要があります

Grid<bool> markAllIncluded();

( numRowsandnumColsはグローバルであるためconst)、または

Grid<bool> markAllIncluded(int numCols, int numRows);

後の定義も同様です。

于 2013-03-10T18:48:13.633 に答える