Hi everyone! I'm working on a program (actually modifying existing code) that simulates a maze when given user input, and what I'm supposed to do is implement a recursive function that will allow a 'mouse' to escape the maze (find the exit). I have done so, the program compiles and executes successfully in VS.net, but when I run it in DevC++, it gives me the following error for each recursive call to the exitCurrCell() function:
123 C:\Documents and Settings\Pbrooks4\My Documents\Visual Studio Projects\Kellett_CS3330_5\Source1.cpp no matching function for call to `Maze::exitCurrCell(Cell)'
It sees the passed parameter as type (Cell) and not (Cell&), a cell object. Any ideas on what is causing this? I like to build in VS.net, because it is a little more user-friendly, but our projects must be compileable in DevC++, because this is what our instructor uses to grade. Code below and attached as a .cpp file. As usual, thanks in advance!
Code:#include <iostream> #include <string> #include <stack> #include <cstdlib> using namespace std; template<class T> class Stack : public stack<T> { public: T pop() { T tmp = stack<T>::top(); stack<T>::pop(); return tmp; } }; class Cell { public: Cell(int i = 0, int j = 0) { x = i; y = j; } bool operator== (const Cell& c) const { return x == c.x && y == c.y; } private: int x, y; friend class Maze; }; class Maze { public: Maze(); void exitCurrCell(Cell&); Cell getEnterCell(); private: Cell currentCell, exitCell, entryCell, currCell; const char exitMarker, entryMarker, visited, passage, wall; Stack<Cell> mazeStack; char **store; // array of strings; void pushUnvisited(int,int); int rows, cols; friend ostream& operator<< (ostream& out, const Maze& maze) { for (int row = 0; row <= maze.rows+1; row++) out << maze.store[row] << endl; out << endl; return out; } }; Maze::Maze() : exitMarker('e'), entryMarker('m'), visited('.'), passage('0'), wall('1') { Stack<char*> mazeRows; char str[80], *s; int col, row = 0; cout << "Enter a rectangular maze using the following " << "characters:\nm - entry\ne - exit\n1 - wall\n0 - passage\n" << "Enter one line at at time; end with Ctrl-z:\n"; while (cin >> str) { row++; cols = strlen(str); s = new char[cols+3]; // two more cells for borderline columns; mazeRows.push(s); strcpy(s+1,str); s[0] = s[cols+1] = wall; // fill the borderline cells with 1s; s[cols+2] = '\0'; if (strchr(s,exitMarker) != 0) { exitCell.x = row; exitCell.y = strchr(s,exitMarker) - s; } if (strchr(s,entryMarker) != 0) { entryCell.x = row; entryCell.y = strchr(s,entryMarker) - s; } } rows = row; store = new char*[rows+2]; // create a 1D array of pointers; store[0] = new char[cols+3]; // a borderline row; for ( ; !mazeRows.empty(); row--) { store[row] = mazeRows.pop(); } store[rows+1] = new char[cols+3]; // another borderline row; store[0][cols+2] = store[rows+1][cols+2] = '\0'; for (col = 0; col <= cols+1; col++) { store[0][col] = wall; // fill the borderline rows with 1s; store[rows+1][col] = wall; } } void Maze::pushUnvisited(int row, int col) { if (store[row][col] == passage || store[row][col] == exitMarker) { mazeStack.push(Cell(row,col)); } } Cell Maze::getEnterCell() { return entryCell; } static int i =0; void Maze::exitCurrCell(Cell& currCell) { i++; cout << i << " "; int row, col; currentCell = currCell; row = currentCell.x; col = currentCell.y; if(!(currentCell == entryCell)) { store[row][col] = visited; } cout << *this << endl; cout << "x = " << currentCell.x << ", y = " << currCell.y << endl; // cout << *this; if(currCell == exitCell) { cout << "The mouse is now out of the maze!" << endl; exit(1); } else { if(store[row-1][col] == passage || store[row-1][col] == exitMarker) { exitCurrCell(Cell(row-1,col)); // Pass cell to this function } if(store[row+1][col] == passage || store[row+1][col] == exitMarker) { exitCurrCell(Cell(row+1, col)); } if(store[row][col-1] == passage || store[row][col-1] == exitMarker) { exitCurrCell(Cell(row, col-1)); } if(store[row][col+1] == passage || store[row][col+1] == exitMarker) { exitCurrCell(Cell(row, col+1)); } } } int main() { Maze myMaze; Cell entCell = myMaze.getEnterCell(); myMaze.exitCurrCell(entCell); return 0; }



LinkBack URL
About LinkBacks


