有人可以向我解释为什么它会在编译时给我这个错误吗?我很久没有接触过C ++了。任何帮助将非常感激。
错误 请求“yello”中的成员“print”,这是非类型'骑士' 错误
class knight
{
public:
knight();
void print();
struct location {
int x;
int y;
};
private:
int size;
int arr[8][8];
};
//initializes the board will -1 and a border of width 2 set to value of 0
knight::knight(){
for(int x = 0; x <= 10; x++){
for(int y = 0; y <= 10; y++){
if(x < 2 || x > 8 || y < 2 || y > 8)
// sets extra padding around the board to ensure no moves off board
arr[x][y] = 0;
else{
arr[x][y] = -1;
}
}
}
}
void knight::print(){
cout<< "\n - - - - - - - - - - - - - - - - - -\n";
for(int i = 2; i <= 8 ;i++){
cout <<"| ";
for(int j = 2; j <= 8 ;j++)
cout << setw(2) << setfill ('0') << arr[i][j]<< " | ";
cout << "\n - - - - - - - - - - - - - - - - - -\n";
}
}
这是主要功能,我在yello.print();
上遇到错误int main(){
cout << " >>> Successful! <<< " << endl;
knight yello();
yello.print();
}