使用默认值c ++标记网格

时间:2013-03-10 18:29:57

标签: c++ grid

我试图在c ++中迭代网格并将每个坐标标记为false。我以为我做的是创建一个25x25的网格,但VC ++给了我两个错误:

(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"

我正在使用stanford c ++ lib来处理我的一些头文件。

这是我的代码:

#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;

}

我的语法错了吗?当我将包含设置为markAllIncluded()l

时,我在main()中得到了错误

2 个答案:

答案 0 :(得分:1)

是的,你的语法错了。功能声明

Grid<bool> markAllIncluded(numCols, numRows);

不正确。你应该使用

Grid<bool> markAllIncluded();

(由于numRowsnumCols是全球const s),或

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

后面的定义也是如此。

答案 1 :(得分:0)

在声明函数时将标识符放在标识符之前

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