c ++期望'else'之前的unqualified-id和'}'令牌错误之前的预期声明

时间:2014-03-22 15:06:44

标签: c++

我一直试着找几分钟找出问题的所在,但没有任何运气。编译时我得到这些错误:

Compiling 'Hero' for 'Arduino Mega 2560 or Mega ADK'
Maze.cpp : expected unqualified-id before 'else'
Maze.cpp : expected unqualified-id before 'else'
Maze.cpp : expected unqualified-id before 'else'
Maze.cpp : expected declaration before '}' token
Error compiling

我已经多次检查了所有括号,我很头疼,请帮我找出错误。

MazeElement Maze::GetElement(byte direction, int distance){
    if (direction == ON_SPOT)
    {
        return Field[PositionX][PositionY];
    } 
    else 
    {
        if (Facing == Maze::NORTH && direction == Maze::FRONT ||
            Facing == Maze::EAST && direction == Maze::LEFT ||
            Facing == Maze::SOUTH && direction == Maze::BACK ||
            Facing == Maze::WEST && direction == Maze::RIGHT)
        {
            if (PositionY-distance >= 0)
                return Field[PositionX][PositionY-distance];
        } 
        else if (Facing == Maze::EAST && direction == Maze::FRONT ||
            Facing == Maze::SOUTH && direction == Maze::LEFT ||
            Facing == Maze::WEST && direction == Maze::BACK ||
            Facing == Maze::NORTH && direction == Maze::RIGHT)
        {
            if (PositionX+distance < sizeof(Field))
                return Field[PositionX+distance][PositionY];
        } 
        else if (Facing == Maze::SOUTH && direction == Maze::FRONT ||
            Facing == Maze::WEST && direction == Maze::LEFT ||
            Facing == Maze::NORTH && direction == Maze::BACK ||
            Facing == Maze::EAST && direction == Maze::RIGHT)
        {
            if (PositionY+distance < sizeof(Field[0]))
                return Field[PositionX][PositionY+distance];
        } 
        else if (Facing == Maze::WEST && direction == Maze::FRONT ||
            Facing == Maze::NORTH && direction == Maze::LEFT ||
            Facing == Maze::EAST && direction == Maze::BACK ||
            Facing == Maze::SOUTH && direction == Maze::RIGHT)
        {
            if (PositionX-distance >= 0)
                return Field[PositionX-distance][PositionY];
        } 
    }
    return NULL;
}

提前谢谢。

0 个答案:

没有答案