2012-09-12 65 views
0

目前,我有一個井字板「tttBoard」與構造問題與構造

tttBoard::tttBoard() { 
    isX = true; 
    for (int x = 0; x < 3; ++x) { 
     for (int y = 0; y < 3; ++y) { 
      gBoard[x][y]=sEmp; 
     } 
    } 
} 

應該創建一個新的董事會,並與枚舉sEmp填充它。 isX是一個布爾值,表示第一個玩家先移動。儘管有#include "tttBoard.h"和(我相信)具有在頭文件(如下圖)構造函數中,我經歷了同樣的錯誤一遍又一遍運行:

error C2589: '(' : illegal token on right side of '::' 
error C2059: syntax error : '::' 
error C2334: unexpected token(s) preceding '{'; skipping apparent function body 

tttBoard.h

#ifndef tttBoard 
#define tttBoard 

class tttBoard { 
public: 
tttBoard(); 
    void   Draw(); 
    void   Move(int x, int y); 
    char*   getValue(int x, int y); 
private: 
    enum sVal { 
     sEmp, 
     sX, 
     sO 
    }; 

    sVal   gBoard[3][3]; 
    bool   isX; 
} 

#endif 
+11

您在類定義的末尾缺少分號。 –

+0

我在頭文件的末尾添加了一個,並得到錯誤'warning C4094:untagged'class'declared'no symbols',我誤解了嗎?感謝您的快速回答 – Chris

+6

@Chris:您的#define tttBoard正在搞砸它。你沒有任何東西代替「tttBoard」標記,這使得你的類聲明變成了'class {' –

回答

2
#ifndef tttBoard 
#define tttBoard 

class tttBoard { 

這不是一個適當的包括警衛。您將tttBoard定義爲空符號,然後爲該類使用相同的名稱。

#ifndef TTT_BOARD_H 
#define TTT_BOARD_H 

class tttBoard { 
    // stuff 
}; 

#endif