1
4

1 回答 1

2

OK, first, you need declarations of CMove, CBoard and CDeadline. I added some dummy ones to allow fixing the other problems:

namespace game {

struct CBoard {};
struct CDeadline {};
struct CMove {};
...

Then, your struct CPlayer::GameData needs to intialize it's CBoard reference, which should be const:

class CPlayer{

        struct GameData
        {
          GameData(const CBoard& board) : pBoard(board) {}
          int mBoard[8][8];
          const CBoard &pBoard;
        };
public:
    CMove Play(const CBoard &pBoard,const CDeadline &pDue);
private:
    int GainsFromMoves(struct GameData gameData);
};

Next, in your .cc file, you need the namespace as well as the class name when defining member functions:

namespace game
{
CMove CPlayer::Play(const CBoard &pBoard,const CDeadline &pDue)
{
     GameData gameData(pBoard);
     return CMove();
}
int CPlayer::GainsFromMoves(GameData gameData){

  int test = 0;

 return test;
}

} // namespace game

This gets rid of the errors, at least with this simple main:

int main()
{
  game::CBoard b;
  game::CDeadline d;
  game::CPlayer p;
  p.Play(b, d);
}
于 2012-09-12T07:31:24.120 回答