Non static members in C++ -


  1. error c2648: 'stack::y' : use of member default parameter requires static member
  2. error c2648: 'stack::x' : use of member default parameter requires static member
  3. intellisense: nonstatic member reference must relative specific object
  4. intellisense: nonstatic member reference must relative specific object

please, fix it

class stack{     node *head, *tail;     int maze[10][10], x, y, _x, _y; public:     stack():head(0), tail(0){};     ~stack();     void load();     void makelist(int = x, int = y); //error here     void push(int, int);     void pop();     void print(); }; void stack::load(){     ifstream fin("maze.txt");     fin >> x >> y >> _x >> _y;     cout << "loaded matrix:" << endl << endl;     (int = 0; < 10; i++){         (int j = 0; j < 10; j++){             fin >> maze[i][j];             if (i == x && j == y)                 cout << "s ";             else if (i == _x && j == _y)                 cout << "f ";             else                 cout << maze[i][j] << " ";         }         cout << endl;     } } void stack::makelist(int x, int y) {     if (x == _x && y == _y)     {         push(x, y);         print();         pop();         return;     }     if (x > 0) if (maze[x - 1][y] == 0) { maze[x][y] = 1; push(x, y); makelist(x - 1, y); pop(); maze[x][y] = 0; }     if (x < 9) if (maze[x + 1][y] == 0) { maze[x][y] = 1; push(x, y); makelist(x + 1, y); pop(); maze[x][y] = 0; }     if (y > 0) if (maze[x][y - 1] == 0) { maze[x][y] = 1; push(x, y); makelist(x, y - 1); pop(); maze[x][y] = 0; }     if (y < 9) if (maze[x][y + 1] == 0) { maze[x][y] = 1; push(x, y); makelist(x, y + 1); pop(); maze[x][y] = 0; } }  <...>  int main() {     stack obj;     obj.load();     obj.makelist();     system("pause");     return 0; } 

(this correction old answer, incorrect)

it seems want use non-static member default value parameter, , compiler tells impossible. can use overload workaround:

class stack{     node *head, *tail;     int maze[10][10], x, y, _x, _y;  public:     void makelist() {makelist(x, y);} // added overload want     void makelist(int x, int x);     ... }; 

some people overloading better using default values, because don't want support calling makelist 1 parameter, 0 or 2 parameters (or, if want this, can add overload, 1 parameter).


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -