对'move'的引用含糊不清

时间:2012-11-07 04:11:29

标签: xcode reference enums ambiguous

在代码的这个特定部分,Xcode发现以下错误:对'move'的引用是不明确的。另外,它说:在交换机中没有处理枚举值'move';这是一个废话,因为包含该值的类。

while(!done){
        //m=rand()%NUM;
        for(m=0;m<NUM;++m){
            if(piece[m].onBoard()){
                sitRep=getIntel(piece,m);
                r=piece[m].recommend(sitRep);
                switch(r){
                    case nothing: break;
                    case lft: piece[mn].turnLeft(); break;
                    case rght: piece[m].turnRight(); break;
                    case rear: piece[m].aboutFace(); break;
                    case move:
                        piece[m].moveForward();
                        if(piece[m].getX()<0||piece[m].getX()>=DIM)piece[m].die();
                        if(piece[m].getY()<0||piece[m].getY()>=DIM)piece[m].die();
                        break;
                    case attck:
                        hits=piece[m].attack();
                        makeSuffer(piece,m,hits);
                        break;
                }
                if(line[0]=='q')done=true;
            }
        }

班级如下:

enum provinceName {anjou, flandre, gascogne, bretagne};
enum compassPoint {U, R, D, L};
enum recommendation {move, nothing, lft, rght, rear, attck};
enum id {empty, ally, enemy, abyss};

// this struct is given to the unit when a recommendation is requested
struct intel{
    id inFront;
    int inFrontNum;

    id inRear;
    int inRearNum;

    id inLeft;
    int inLeftNum;

    id inRight;
    int inRightNum;

    compassPoint nearestEnemyDir;
    int nearestEnemyDist;
    int nearestEnemyNum;

    compassPoint weakestEnemyDir;
    int weakestEnemyDist;
    int weakestEnemyNum;

    compassPoint strongestEnemyDir;
    int strongestEnemyDist;
    int strongestEnemyNum;

    compassPoint nearestAllyDir;
    int nearestAllyDist;
    int nearestAllyNum;

    compassPoint weakestAllyDir;
    int weakestAllyDist;
    int weakestAllyNum;

    compassPoint strongestAllyDir;
    int strongestAllyDist;
    int strongestAllyNum;
};

class gamePiece{
public:
    // return the status of the alive variable
    bool onBoard();

    // return the current x value
    int getX();

    // return the current y value
    int getY();

    // return the current direction
    compassPoint getDir();

    // return the number of soldiers in the unit
    int getNumElements();

    // return the province
    provinceName getProvince();

    // set alive to false
    void die();

    // change the direction for a left turn
    void turnLeft();

    // change the direction for right turn
    void turnRight();

    // change the direction for an about face
    void aboutFace();

    // change x and y for a forward move
    void moveForward();

    // roll a die for each soldier in the unit.
    // each 5 or 6 counts as a 'hit'.
    // return the number of hits.
    int attack();

    //return lft, rght, rear, move, attck, or nothing
    recommendation recommend(intel sitRep);

    // reduce the number of soldiers by hits
    int suffer(int hits);

    // construct a nonliving gamepiece
    gamePiece();

    // construct a living gamepeice
    gamePiece(int col, int row, compassPoint direction, int num, provinceName p);

private:
    int numSoldiers;
    int x;
    int y;
    compassPoint dir;
    provinceName province;
    bool alive;

};

有人可以找出似乎是什么问题吗? 谢谢。

1 个答案:

答案 0 :(得分:1)

可能是case lft:piece [mn] .turnLeft();打破;?什么是mn?它不应该只是m?顺便说一句,我也在做同样的工作。