Menu

-fpermissive compiler error

2008-12-02
2012-09-26
  • Matt Monroe

    Matt Monroe - 2008-12-02

    Hey everybody,
    I am trying to get started on a homework assignment. I have copied the file given on the authors website (this is a modification for efficiency assignment) into my main.cpp file. I am trying to compile and run this code before inserting any new code or modifications:

    <code>

    include <iostream>

    include <string>

    include <stack>

    using namespace std;

    template<class T>
    class Stack : public stack<T> {
    public:
    T pop() {
    T tmp = 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 exitMaze();
    private:
    Cell currentCell, exitCell, entryCell;
    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));
    }
    }
    void Maze::exitMaze() {
    int row, col;
    currentCell = entryCell;
    while (!(currentCell == exitCell)) {
    row = currentCell.x;
    col = currentCell.y;
    cout << this; // print a snapshot;
    if (!(currentCell == entryCell))
    store[row][col] = visited;
    pushUnvisited(row-1,col);
    pushUnvisited(row+1,col);
    pushUnvisited(row,col-1);
    pushUnvisited(row,col+1);
    if (mazeStack.empty()) {
    cout <<
    this;
    cout << "Failure\n";
    return;
    }
    else currentCell = mazeStack.pop();
    }
    cout << *this;
    cout << "Success\n";
    }

    int main() {
    Maze().exitMaze();
    return 0;
    }

    </code>
    The code:
    <code>
    template<class T>
    class Stack : public stack<T> {
    public:
    T pop() {
    T tmp = top(); //<-------------------------------------this is the line throwing the error
    stack<T>::pop();
    return tmp;
    }
    </code>
    Errors thrown are:
    C:\Dev-Cpp\MazeRecursion\main.cpp In member function `T Stack<T>::pop()':

    11 C:\Dev-Cpp\MazeRecursion\main.cpp there are no arguments to top' that depend on a template parameter, so a declaration oftop' must be available

    11 C:\Dev-Cpp\MazeRecursion\main.cpp (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

    C:\Dev-Cpp\MazeRecursion\Makefile.win [Build Error] [main.o] Error 1

    I am under the impression that no one else, using other compilers, is having this problem.
    I also am under the impression through searching the internet that these errors can be fixed by setting this -fpermissive flag with a preprocessor directive. I have been unable, after several searches and trials to find what directive this flag belongs to. Any help or direction would be greatly appreciated.
    Thanks alot!
    Matt

     
    • cpns

      cpns - 2008-12-02

      > I am under the impression that no one else,
      > using other compilers, is having this problem.

      Other compilers are then 'permissive' by default. For commercial compilers, it is not in their interest to gratuitously fail to build their customers previously working code, so that are generally slower to remove deprecated behaviour, or they don't remove it at all. VC++ 2008 does not reject it, but if you turn the warning level up to max it does emit the following:

      c:\projects\testcode\sandbox\main.cpp(47) : warning C4512: 'Maze' : assignment operator could not be generated
      c:\projects\testcode\sandbox\main.cpp(30) : see declaration of 'Maze'

      > [...]can be fixed by setting this -fpermissive flag with a preprocessor directive.

      That is not a pre=processor directive, it is a compiler command line option.

      > I have been unable, after several searches and
      > trials to find what directive this flag belongs to

      Probably because you were looking in the wrong place. http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options (i.e. the manual!)
      [quote]
      -fpermissive
      Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile.
      [unquote]

      Fixing it is better though. Letting teh author know might be a good idea too.

      Clifford

       
    • Matt Monroe

      Matt Monroe - 2008-12-02

      I forgot to say that everything I am finding on this issue is with linux and none of the fixes are working. Not sure if it matters but I am running Dev on a vista machine.
      Thanks
      Matt

       
    • Matt Monroe

      Matt Monroe - 2008-12-02

      Ha nevermind!
      just fixed it change the line throwing the error to
      T tmp = this ->top(); and voila!

      Matt

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.