Thread: DevC++ different than VS.net C++? - problem!

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    121

    DevC++ different than VS.net C++? - problem!

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

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Code:
    exitCurrCell(Cell(row-1,col));
    You cannot pass a temporary when the expected parameter is a non-const reference. It's one of the reasons why you should use const by default and only not use it when it doesn't work with const.

    change exitCurrCell prototype to void exitCurrCell(const Cell&). Don't forget to also alter the definition.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Thanks Mario, I'll do that when I get home.

    -Patrick

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Yeah, that seemed to do it. Muito obrigado, Mario! :-) Thanks for the info!

    -Patrick

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. A VS.NET Problem
    By Korn1699 in forum Tech Board
    Replies: 1
    Last Post: 11-23-2002, 08:33 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM