我在我的主(全局)頭文件中的類中存在一些循環聲明的情況。C++通告聲明
#include <cstdlib>
#include <iostream>
using namespace std;
enum piece_t {BLACK, WHITE, EMPTY, WALL}; //wall is area out side of board (board array is 21x21 but only 19x19 is playable)
enum dir_t {ABOVE,BELOW,LEFT, RIGHT}; //shall i overload ! or - operatior? !LEFT==RIGHT?
struct nextPoint_t //should be implimented with references, but need to practice pointer
{
point_t* above;
point_t* below;
point_t* left;
point_t* right;
};
class point_t
{
private:
piece_t mType; //what sort of point this is
int mLiberties;
nextPoint_t mAdjacent; // points to adjacent points
bool mLibertiesCounted; // keeps track of if liberties have been counted, for mCountLiberites() (sets), is reset by mUpdateLiberites();
int mCountLiberties(); //counts this point's liberites, by calling count on mAdjacent points etc.
void mSetPos(int xPos, int yPos, board_t theBoard); //sets up mAdjacent to point to adjacent points,
void mSetStructureLiberties(int numLibs); // Sets this squares liberites then calls this on all adjacent squares
public:
point_t();// parameterless constructor, for arrays
void mSetUp(int xPos, int yPos, board_t theBoard);// sets up mType then calles setPos iFF not WALL type
point_t (int xPos, int yPos, board_t theBoard); //constructor, takes it's position in the grid as a parameter
void mUpdateLiberties(); // calles countLiberties then, updates liberites on whole of connected structure, by operating pon all conencted points
};
class board_t
{
private:
point_t mArray [21][21];
public:
board_t(); //constructor, sets up board by operating on the point_t's
};
不要擔心那裏的評論,我知道我的意思。
我想我可以向聲明修復它,但他們似乎沒有工作,只是認爲我redeifining類
循環聲明在哪裏?一切似乎都正確地宣告了 – dharga 2009-09-25 14:31:31
哦,是point_t *在struct nextPoint_t中的問題嗎? – dharga 2009-09-25 14:33:01
循環依賴總是讓我感到腥味。它看起來像你可以重構你的代碼,以避免它們。 – luke 2009-09-25 14:34:21