简体   繁体   中英

marking a grid with default values c++

I am trying to iterate through a grid in c++ and mark every coordinate as false. What I thought I had done was create a 25x25 grid but VC++ is giving me two errors:

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

I am using the stanford c++ lib for some of my header files.

Here is my code:

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

}

Is my syntax wrong? I get my error in main() when I set included to markAllIncluded()l

Yeah, your syntax is wrong. The function declaration

Grid<bool> markAllIncluded(numCols, numRows);

is incorrect. You should use

Grid<bool> markAllIncluded();

(since numRows and numCols are global const s), or

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

Same goes for the definition later.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM