[英]marking a grid with default values c++
我試圖遍歷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;
}
我的語法錯誤嗎? 當我將include設置為markAllIncluded()l時,在main()中出現錯誤
是的,您的語法錯誤。 函數聲明
Grid<bool> markAllIncluded(numCols, numRows);
是不正確的。 你應該用
Grid<bool> markAllIncluded();
(因為numRows
和numCols
是全局const
),或者
Grid<bool> markAllIncluded(int numCols, int numRows);
以后的定義也一樣。
聲明函數時,將類型放在標識符之前
Grid<bool> markAllIncluded(int numCols, int numRows)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.