0

コードのこの特定の部分で、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;

};

誰かが問題と思われるものを見つけてくれませんか?ありがとうございました。

4

1 に答える 1

1

そうかもしれません lft: piece[mn].turnLeft(); 壊す;?mnは?mだけじゃないの?ちなみに私も同じ担当です。

于 2012-11-09T04:19:04.517 に答える