0

Can someone explain to me why it's giving me this error on compilation? I haven't touched C++ in a long time. Any help would be much appreciated.

error request for member “print” in “yello” which is of non-class type 'knight' error

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";
    }
}

Here is the main function and I'm getting error on yello.print();

int main(){
cout << " >>> Successful! <<< " << endl;
knight yello();
yello.print();

}
Cody Krauskopf
  • 330
  • 1
  • 4
  • 13

0 Answers0