0

次のエラーの処理に問題があります。

c2660: c:\users\lukas plaehn\desktop\oop\sokoban\sokoban\main.cpp(126): エラー C2660: 'CPlayer::moveUp': 関数は引数を 1 つ取りません

c2061: c:\users\lukas plaehn\desktop\oop\sokoban\sokoban\player.h(10): エラー C2061: 構文エラー: 識別子 'CMaze'

私がやろうとしているのは、オブジェクトをヘッダー ファイルのパラメーターとして渡すことです。私も参照して試してみましたが、うまくいきません。CMazeどういうわけか、コンパイラは、ヘッダー ファイル内の型の宣言を許可していませんCPlayer

    class CPlayer:public CBlocks
    {
    public:
    CMaze * m;
    CPlayer(void);
    CPlayer(char sym, int x, int y, CMaze mz);
    ~CPlayer(void);
    void moveUp(CMaze maze);
    void moveDown(CMaze maze);
    void moveLeft(CMaze maze);
    void moveRight(CMaze maze);
};

    #include "Player.h"
    #include "Maze.h"
    //#include "headers.h"




    CPlayer::CPlayer(void)
    {
    }

    CPlayer::CPlayer(char sym, int x, int y, CMaze mz)
    {
    m = &mz;
    m_symbol = sym;
    m_x = x;
    m_y = y;
    }

    CPlayer::~CPlayer(void)
    {
    }



    void CPlayer::moveDown(CMaze maze)
    {
    if(m->arr[m_y+1][m_x].m_symbol == ' ')
    {
        m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
        m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
    }
    else if(m->arr[m_y+1][m_x].m_symbol == '#')
    {
        cout << "You cannot perform this move!"<<endl;
    }
    else if(m->arr[m_y+1][m_x].m_symbol == '$')
    {
        if(m->arr[m_y+2][m_x].m_symbol == ' ')
        {
            m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
            m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
            m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '.')
        {
            m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
            m->arr[m_y+2][m_x].m_symbol = '*';
            m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
            m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   

    }

    else if(m->arr[m_y+1][m_x].m_symbol == '.')
    {
        m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
        m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        m->arr[m_y+1][m_x].m_symbol = '+';
    }
    else if(m->arr[m_y+1][m_x].m_symbol == '*')
    {
        if(m->arr[m_y+2][m_x].m_symbol == ' ')
        {
            m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
            m->arr[m_y+2][m_x].m_symbol = '$';
            m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
            m->arr[m_y+1][m_x].m_symbol = '+';
            m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '.')
        {
            m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
            m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
            m->arr[m_y+1][m_x].m_symbol = '+';
            m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(m->arr[m_y+2][m_x].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   
    }


    }

    void CPlayer::moveUp(CMaze maze)
    {
    if(maze.arr[m_y-1][m_x].m_symbol == ' ')
    {
        maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
        maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
    }
    else if(maze.arr[m_y-1][m_x].m_symbol == '#')
    {
        cout << "You cannot perform this move!"<<endl;
    }
    else if(maze.arr[m_y-1][m_x].m_symbol == '$')
    {
        if(maze.arr[m_y-2][m_x].m_symbol == ' ')
        {
            maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
            maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '.')
        {
            maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
            maze.arr[m_y-2][m_x].m_symbol = '*';
            maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   

    }

    else if(maze.arr[m_y-1][m_x].m_symbol == '.')
    {
        maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
        maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        maze.arr[m_y-1][m_x].m_symbol = '+';
    }
    else if(maze.arr[m_y-1][m_x].m_symbol == '*')
    {
        if(maze.arr[m_y-2][m_x].m_symbol == ' ')
        {
            maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
            maze.arr[m_y-2][m_x].m_symbol = '$';
            maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
            maze.arr[m_y-1][m_x].m_symbol = '+';
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '.')
        {
            maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
            maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
            maze.arr[m_y-1][m_x].m_symbol = '+';
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y-2][m_x].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   
    }
    }

    void CPlayer::moveLeft(CMaze maze)
    {
    if(maze.arr[m_y][m_x-1].m_symbol == ' ')
    {
        maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
        maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
    }
    else if(maze.arr[m_y][m_x-1].m_symbol == '#')
    {
        cout << "You cannot perform this move!"<<endl;
    }
    else if(maze.arr[m_y][m_x-1].m_symbol == '$')
    {
        if(maze.arr[m_y][m_x-2].m_symbol == ' ')
        {
            maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
            maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x-1].m_symbol == '.')
        {
            maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
            maze.arr[m_y][m_x-2].m_symbol = '*';
            maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   

    }

    else if(maze.arr[m_y][m_x-1].m_symbol == '.')
    {
        maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
        maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        maze.arr[m_y][m_x-1].m_symbol = '+';
    }
    else if(maze.arr[m_y][m_x-1].m_symbol == '*')
    {
        if(maze.arr[m_y][m_x-2].m_symbol == ' ')
        {
            maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
            maze.arr[m_y][m_x-2].m_symbol = '$';
            maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x-1].m_symbol = '+';
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '.')
        {
            maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
            maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x-1].m_symbol = '+';
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x-2].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   
    }
    }

    void CPlayer::moveRight(CMaze maze)
    {
    if(maze.arr[m_y][m_x+1].m_symbol == ' ')
    {
        maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
        maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
    }
    else if(maze.arr[m_y][m_x+1].m_symbol == '#')
    {
        cout << "You cannot perform this move!"<<endl;
    }
    else if(maze.arr[m_y][m_x+1].m_symbol == '$')
    {
        if(maze.arr[m_y][m_x+2].m_symbol == ' ')
        {
            maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
            maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x+1].m_symbol == '.')
        {
            maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
            maze.arr[m_y][m_x+2].m_symbol = '*';
            maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   

    }

    else if(maze.arr[m_y][m_x+1].m_symbol == '.')
    {
        maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
        maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        maze.arr[m_y][m_x+1].m_symbol = '+';
    }
    else if(maze.arr[m_y][m_x+1].m_symbol == '*')
    {
        if(maze.arr[m_y][m_x+2].m_symbol == ' ')
        {
            maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
            maze.arr[m_y][m_x+2].m_symbol = '$';
            maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x+1].m_symbol = '+';
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '.')
        {
            maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
            maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
            maze.arr[m_y][m_x+1].m_symbol = '+';
            maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '$')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '#')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else if(maze.arr[m_y][m_x+2].m_symbol == '*')
        {
            cout << "You cannot perform this move!" << endl;
        }
        else
        {
            cout << "Unkown Error Occurred" << endl;
        }   
    }
    }


    class CMaze
    {
public:
    friend class CPlayer;

    int m_columns, m_rows;
    string line;
    CBlocks arr[32][48];
    int i, j;
    int k, count;
    bool m_status;


    ifstream mazeStream;


    CMaze(void);
    ~CMaze(void);
    void setStatus(CMaze maze);
    CBlocks fillCharArr();
    void displayMaze();

    };
4

2 に答える 2

0

これは、player.h から迷路ヘッダーを含めていないという事実と関係があると思います...これは、値で渡す場合 (不要なコピーが発生するため悪いことです)、関数CMaze オブジェクトを使用したいにもかかわらず、CMaze オブジェクトについて何も知りません。

CMaze をポインターまたは参照として渡せば、問題は解決すると思います。ただし、これを行うことにより、関数内で CMaze を後で変更すると、渡された CMaze も変更されることに注意する必要があります。

于 2012-05-29T13:17:55.513 に答える
0

CMaze を前方宣言し、参照渡しすると、c2061 が処理されます。

class CMaze;
class CPlayer : public CBlocks
{
    public:
    CMaze * m;
    CPlayer(void);
    CPlayer(char sym, int x, int y, CMaze & mz);
    ~CPlayer(void);
    void moveUp(CMaze & maze);
    void moveDown(CMaze & maze);
    void moveLeft(CMaze & maze);
    void moveRight(CMaze & maze);
}:
于 2012-05-29T13:12:57.300 に答える